first commit

This commit is contained in:
Steffen Junge committed 2025-04-09 21:36:51 +02:00
commit 6f4ad5c40c
154 files changed
+887972

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
#!/usr/bin/perl -w
use strict;
use warnings;
use DBI;
use Data::Dumper;
# use JSON;
use Getopt::Long;
use File::Slurp qw(:std);
use Term::ANSIColor;
my $inhalt; # Refrenztdaten aus der JSON Datei
my $write = 0; # Parameter zum schreiben der Datei
my $fileexist = 1; # Existiert die angegene Datei nicht wird sie zu 0 und eine Meldung erscheint
my $db = "prod"; # Datenbankparameter
my $user = "root"; # Datenbankuser
my $pass = "jagger"; # Datenbankpasswort
my $server = "ares"; # Datenbankserver
my $result = ""; # ergebnis des Vergleichens
my $wid = "37451383";
my $dbh = DBI->connect("DBI:mysql:$db:$server", $user, $pass)
#my $dbh = DBI->connect('DBI:mysql:prod:ares', 'root', 'jagger')
or die "Couldn't connect to database: " . DBI->errstr;
my $sql = "SELECT xval FROM prv_masterxt where wid=? and xkey='Parameterblock'";
my $selectrow_array = $dbh->selectrow_array($sql, undef, $wid);
print Dumper( $selectrow_array );
my $selectrow_arrayref = $dbh->selectrow_arrayref($sql, undef, $wid);
print Dumper( $selectrow_arrayref);
my $selectrow_hashref = $dbh->selectrow_hashref($sql, undef, $wid);
print Dumper( $selectrow_hashref);
my $selectall_arrayref = $dbh->selectall_arrayref($sql, { Slice => {} }, $wid);
print Dumper( $selectall_arrayref);
my $selectall_arrays = $dbh->selectall_arrayref($sql, undef, $wid);
print Dumper( $selectall_arrays);
$dbh->disconnect;
1;
+3
View File
@@ -0,0 +1,3 @@
[prv]
lastbndid=240047
lastwid=3471157
+597
View File
@@ -0,0 +1,597 @@
#!/usr/bin/perl -w
use Config::Tiny;
use strict;
use warnings;
use DBI;
use Data::Dumper;
use JSON;
use Getopt::Long;
use File::Slurp qw(:std);
use POSIX qw(strftime);
use IO::Handle;
use File::Path qw(make_path);
STDOUT->autoflush(1);
#https://www.easysoft.com/developer/languages/perl/dbd_odbc_tutorial_part_2.html
# use Term::ANSIColor;
# Create a config
my $Config = Config::Tiny->new;
# Open the config
$Config = Config::Tiny->read( 'prvbackup.ini', 'utf8' );
my $db = "prod"; # Datenbank
my $user = "prv19"; # Datenbankuser
my $pass = "!nd!4n3R"; # Datenbankpasswort
my $server = "jupiter"; # Datenbankserver
my $tref; # dient zur analyse welcher Datentyp die Spalte hat
my $text; # wird mit den Daten zum schreiben in die datei gefüllt
my @tabelle;
my $maxlength = 1000000;
my $datei = "temp.sql";
my $datei2 = "temp2.sql";
my $dbh = DBI->connect("DBI:mysql:$db:$server", $user, $pass) or die "Couldn't connect to database: " . DBI->errstr;
sub _getinsert {
# hier wird entschieden wie die einzelnen Daten in abhängigkeit des Datentyps geschrieben werden
# es kommen die gemerkten Spalten (@tabelle) und Datentypen ($tref) zum Einsatz
# zb: mit Strings mit '' integer ohne '', umgang mit zeilenumbrüchen, blobs
# bei einem unbekannten typ kommt der Dumper
my ( $d, $n ) = @_;
my $text;
for my $col( @tabelle ) {
if ( defined $d->{$col} ) {
if ( $tref->{ $n }->{$col} =~ /int|year|double|decimal|float/ ) {
$text .= $d->{$col}.","
} elsif ($tref->{ $n }->{$col} =~ /char|date|time|enum|text/ ) {
$d->{$col} =~ s/\\/\\\\/g;
$d->{$col} =~ s/\n/\\n/g;
$d->{$col} =~ s/\r/\\n/g;
$d->{$col} =~ s/\r\n\\/\\n/g;
$d->{$col} =~ s/\'/\\'/g;
$text .= "'".$d->{$col}."',"
} elsif ($tref->{ $n }->{$col} =~ /blob/ ) {
$text .= "_binary 0x". uc unpack("H*",$d->{$col}).",";
} else {
print Dumper($tref->{ $n }->{$col});
}
} else {
$text .= "NULL,";
}
}
return $text;
}
sub _gettype {
my ( $n ) = @_;
my $s2 = $dbh->selectall_arrayref("DESCRIBE $n" , { Slice => {} });
my $i = "";
@tabelle = ();
# hier wird sich der Datentyp einer Spalte gemerkt
# und ein Array mit den Spaltenamen
for my $s ( @{$s2} ) {
my $f = $s->{Field};
$tref->{ $n }->{$f} = $s->{Type};
push @tabelle, $s->{Field};
$i .= $s->{Field}.',';
}
$i =~ s/,$//; # letzes , insert entfernen
return "INSERT INTO $n ( $i ) VALUES";
}
# Ordner erstellen wenn nicht bekannt
# if (!-d "$server/$db") {
# make_path "$server/$db";
# }
for my $c (1..5) {
my @wids;
my @panelids;
my @cpids;
my @bndids;
my $datei = "temp.sql";
my $datei2 = "temp2.sql";
write_file($datei, '' );
# Insert Kopf erstellen
######################################################################
my $cnt = 0;
my $len = 0; # Zähler für die maximale Länge in Bytes eines Insert
my $tbl = 'prv_master';
my $inserttext = _gettype($tbl);
my $startwid = $Config->{prv}->{lastwid};
my $sth = $dbh->prepare("SELECT * from $tbl where wid > $startwid order by wid limit 50000"); # prepare the query
# in der Schleife werden die einzelnen inserts direkt in die Datei geschrieben, geht schneller als wenn man die inserts sammelt und dann erst schreibt
$sth->execute(); # execute the query with parameter
my $max = $sth->rows;
# Holen der Daten
while (my $d = $sth->fetchrow_hashref) { # retrieve one row
$cnt += 1;
push @wids, $d->{wid};
$Config->{prv}->{lastwid} = $d->{wid};
if ( $len == 0 ) { # bei 0 wird ein neues Create statement erzeugt
append_file($datei, $inserttext );
}
$text = "\n("; # Klammer für insert erstellen
$text .= _getinsert( $d, $tbl);
$len += length($text); # zählen der Länge der inserts es werden auch die , _binary
$text =~ s/,$//; # letzes , insert entfernen
$text .= "),"; # und Klammer wieder schließen
if ( $cnt == $max or ($len > $maxlength and $maxlength != 0 ) ) { # wenn maximale Länge eines insert oder Ende der Tabelle erreicht , gegen ; tauschen und Zähler auf 0
$len = 0;
$text =~ s/,$/;\n/;
}
append_file($datei, $text );
print "$cnt - $max\r";
}
print " ---> $tbl ready\n";
###########################################################################
$cnt = 0;
$len = 0; # Zähler für die maximale Länge in Bytes eines Insert
$tbl = "prv_mac";
$inserttext = _gettype($tbl);
my $wid = join(',' , @wids);
if ( $wid ne '' ) {
$sth = $dbh->prepare("SELECT * from $tbl where wid in ($wid)" ); # prepare the query
# in der Schleife werden die einzelnen inserts direkt in die Datei geschrieben, geht schneller als wenn man die inserts sammelt und dann erst schreibt
$sth->execute() ; # execute the query with parameter
$max = $sth->rows;
# Holen der Daten
while (my $d = $sth->fetchrow_hashref) { # retrieve one row
$cnt += 1;
if ( $len == 0 ) { # bei 0 wird ein neues Create statement erzeugt
append_file($datei, $inserttext );
}
$text = "\n("; # Klammer für insert erstellen
$text .= _getinsert( $d, $tbl);
$len += length($text); # zählen der Länge der inserts es werden auch die , _binary
$text =~ s/,$//; # letzes , insert entfernen
$text .= "),"; # und Klammer wieder schließen
if ( $cnt == $max or ($len > $maxlength and $maxlength != 0 ) ) { # wenn maximale Länge eines insert oder Ende der Tabelle erreicht , gegen ; tauschen und Zähler auf 0
$len = 0;
$text =~ s/,$/;\n/;
}
append_file($datei, $text );
print "$cnt - $max\r";
}
}
print " ---> $tbl ready\n";
$cnt = 0;
$len = 0; # Zähler für die maximale Länge in Bytes eines Insert
$tbl = "prv_masterxt";
if ( $wid ne '' ) {
$inserttext = _gettype($tbl);
$sth = $dbh->prepare("SELECT * from $tbl where wid in ($wid)" ); # prepare the query
# in der Schleife werden die einzelnen inserts direkt in die Datei geschrieben, geht schneller als wenn man die inserts sammelt und dann erst schreibt
$sth->execute() ; # execute the query with parameter
$max = $sth->rows;
# Holen der Daten
while (my $d = $sth->fetchrow_hashref) { # retrieve one row
$cnt += 1;
if ( $len == 0 ) { # bei 0 wird ein neues Create statement erzeugt
append_file($datei, $inserttext );
}
$text = "\n("; # Klammer für insert erstellen
$text .= _getinsert( $d, $tbl);
$len += length($text); # zählen der Länge der inserts es werden auch die , _binary
$text =~ s/,$//; # letzes , insert entfernen
$text .= "),"; # und Klammer wieder schließen
if ( $cnt == $max or ($len > $maxlength and $maxlength != 0 ) ) { # wenn maximale Länge eines insert oder Ende der Tabelle erreicht , gegen ; tauschen und Zähler auf 0
$len = 0;
$text =~ s/,$/;\n/;
}
append_file($datei, $text );
print "$cnt - $max\r";
}
}
print " ---> $tbl ready\n";
$cnt = 0;
$len = 0; # Zähler für die maximale Länge in Bytes eines Insert
$tbl = 'prv_mount';
if ( $wid ne '' ) {
$inserttext = _gettype($tbl);
$sth = $dbh->prepare("SELECT * from $tbl where master in ($wid)" ); # prepare the query
# in der Schleife werden die einzelnen inserts direkt in die Datei geschrieben, geht schneller als wenn man die inserts sammelt und dann erst schreibt
$sth->execute() ; # execute the query with parameter
$max = $sth->rows;
# Holen der Daten
while (my $d = $sth->fetchrow_hashref) { # retrieve one row
$cnt += 1;
if ( $len == 0 ) { # bei 0 wird ein neues Create statement erzeugt
append_file($datei, $inserttext );
}
$text = "\n("; # Klammer für insert erstellen
$text .= _getinsert( $d, $tbl);
$len += length($text); # zählen der Länge der inserts es werden auch die , _binary
$text =~ s/,$//; # letzes , insert entfernen
$text .= "),"; # und Klammer wieder schließen
if ( $cnt == $max or ($len > $maxlength and $maxlength != 0 ) ) { # wenn maximale Länge eines insert oder Ende der Tabelle erreicht , gegen ; tauschen und Zähler auf 0
$len = 0;
$text =~ s/,$/;\n/;
}
append_file($datei, $text );
print "$cnt - $max\r";
}
}
print " ---> $tbl ready\n";
$cnt = 0;
$len = 0; # Zähler für die maximale Länge in Bytes eines Insert
$tbl = 'prv_chkpnt';
if ( $wid ne '' ) {
$inserttext = _gettype($tbl);
$sth = $dbh->prepare("SELECT * from $tbl where wid in ($wid)" ); # prepare the query
# in der Schleife werden die einzelnen inserts direkt in die Datei geschrieben, geht schneller als wenn man die inserts sammelt und dann erst schreibt
$sth->execute() ; # execute the query with parameter
$max = $sth->rows;
# Holen der Daten
while (my $d = $sth->fetchrow_hashref) { # retrieve one row
$cnt += 1;
push @cpids, $d->{cpid};
if ( $len == 0 ) { # bei 0 wird ein neues Create statement erzeugt
append_file($datei, $inserttext );
}
$text = "\n("; # Klammer für insert erstellen
$text .= _getinsert( $d, $tbl);
$len += length($text); # zählen der Länge der inserts es werden auch die , _binary
$text =~ s/,$//; # letzes , insert entfernen
$text .= "),"; # und Klammer wieder schließen
if ( $cnt == $max or ($len > $maxlength and $maxlength != 0 ) ) { # wenn maximale Länge eines insert oder Ende der Tabelle erreicht , gegen ; tauschen und Zähler auf 0
$len = 0;
$text =~ s/,$/;\n/;
}
append_file($datei, $text );
print "$cnt - $max\r";
}
}
print " ---> $tbl ready\n";
$cnt = 0;
$len = 0; # Zähler für die maximale Länge in Bytes eines Insert
$tbl = 'prv_mkz';
my $cpid = join(',' , @cpids);
if ( $cpid ne '' ) {
$inserttext = _gettype($tbl);
$sth = $dbh->prepare("SELECT * from $tbl where cpid in ($cpid)" ); # prepare the query
# in der Schleife werden die einzelnen inserts direkt in die Datei geschrieben, geht schneller als wenn man die inserts sammelt und dann erst schreibt
$sth->execute() ; # execute the query with parameter
$max = $sth->rows;
# Holen der Daten
while (my $d = $sth->fetchrow_hashref) { # retrieve one row
$cnt += 1;
if ( $len == 0 ) { # bei 0 wird ein neues Create statement erzeugt
append_file($datei, $inserttext );
}
$text = "\n("; # Klammer für insert erstellen
$text .= _getinsert( $d, $tbl);
$len += length($text); # zählen der Länge der inserts es werden auch die , _binary
$text =~ s/,$//; # letzes , insert entfernen
$text .= "),"; # und Klammer wieder schließen
if ( $cnt == $max or ($len > $maxlength and $maxlength != 0 ) ) { # wenn maximale Länge eines insert oder Ende der Tabelle erreicht , gegen ; tauschen und Zähler auf 0
$len = 0;
$text =~ s/,$/;\n/;
}
append_file($datei, $text );
print "$cnt - $max\r";
}
print " ---> $tbl ready\n";
}
$cnt = 0;
$len = 0; # Zähler für die maximale Länge in Bytes eines Insert
$tbl = 'prv_xtxt';
if ( $cpid ne '' ) {
$inserttext = _gettype($tbl);
$sth = $dbh->prepare("SELECT * from $tbl where cpid in ($cpid)" ); # prepare the query
# in der Schleife werden die einzelnen inserts direkt in die Datei geschrieben, geht schneller als wenn man die inserts sammelt und dann erst schreibt
$sth->execute() ; # execute the query with parameter
$max = $sth->rows;
# Holen der Daten
while (my $d = $sth->fetchrow_hashref) { # retrieve one row
$cnt += 1;
if ( $len == 0 ) { # bei 0 wird ein neues Create statement erzeugt
append_file($datei, $inserttext );
}
$text = "\n("; # Klammer für insert erstellen
$text .= _getinsert( $d, $tbl);
$len += length($text); # zählen der Länge der inserts es werden auch die , _binary
$text =~ s/,$//; # letzes , insert entfernen
$text .= "),"; # und Klammer wieder schließen
if ( $cnt == $max or ($len > $maxlength and $maxlength != 0 ) ) { # wenn maximale Länge eines insert oder Ende der Tabelle erreicht , gegen ; tauschen und Zähler auf 0
$len = 0;
$text =~ s/,$/;\n/;
}
append_file($datei, $text );
print "$cnt - $max\r";
}
print " ---> $tbl ready\n";
}
$cnt = 0;
$len = 0; # Zähler für die maximale Länge in Bytes eines Insert
$tbl = 'prv_panel';
if ( $wid ne '' ) {
$inserttext = _gettype($tbl);
$sth = $dbh->prepare("SELECT * from $tbl where wid in ($wid)" ); # prepare the query
# in der Schleife werden die einzelnen inserts direkt in die Datei geschrieben, geht schneller als wenn man die inserts sammelt und dann erst schreibt
$sth->execute() ; # execute the query with parameter
$max = $sth->rows;
# Holen der Daten
while (my $d = $sth->fetchrow_hashref) { # retrieve one row
$cnt += 1;
push @panelids, $d->{panelid};
if ( $len == 0 ) { # bei 0 wird ein neues Create statement erzeugt
append_file($datei, $inserttext );
}
$text = "\n("; # Klammer für insert erstellen
$text .= _getinsert( $d, $tbl);
$len += length($text); # zählen der Länge der inserts es werden auch die , _binary
$text =~ s/,$//; # letzes , insert entfernen
$text .= "),"; # und Klammer wieder schließen
if ( $cnt == $max or ($len > $maxlength and $maxlength != 0 ) ) { # wenn maximale Länge eines insert oder Ende der Tabelle erreicht , gegen ; tauschen und Zähler auf 0
$len = 0;
$text =~ s/,$/;\n/;
}
append_file($datei, $text );
print "$cnt - $max\r";
}
}
print " ---> $tbl ready\n";
$cnt = 0;
$len = 0; # Zähler für die maximale Länge in Bytes eines Insert
$tbl = 'prv_panelcp';
my $panelid = join(',' , @panelids);
if ( $panelid ne '' ) {
$inserttext = _gettype($tbl);
$sth = $dbh->prepare("SELECT * from $tbl where panelid in ($panelid)" ); # prepare the query
# in der Schleife werden die einzelnen inserts direkt in die Datei geschrieben, geht schneller als wenn man die inserts sammelt und dann erst schreibt
$sth->execute() ; # execute the query with parameter
$max = $sth->rows;
# Holen der Daten
while (my $d = $sth->fetchrow_hashref) { # retrieve one row
$cnt += 1;
if ( $len == 0 ) { # bei 0 wird ein neues Create statement erzeugt
append_file($datei, $inserttext );
}
$text = "\n("; # Klammer für insert erstellen
$text .= _getinsert( $d, $tbl);
$len += length($text); # zählen der Länge der inserts es werden auch die , _binary
$text =~ s/,$//; # letzes , insert entfernen
$text .= "),"; # und Klammer wieder schließen
if ( $cnt == $max or ($len > $maxlength and $maxlength != 0 ) ) { # wenn maximale Länge eines insert oder Ende der Tabelle erreicht , gegen ; tauschen und Zähler auf 0
$len = 0;
$text =~ s/,$/;\n/;
}
append_file($datei, $text );
print "$cnt - $max\r";
}
}
print " ---> $tbl ready\n";
$cnt = 0;
$len = 0; # Zähler für die maximale Länge in Bytes eines Insert
$tbl = 'prv_panelmaster';
if ( $panelid ne '' ) {
$inserttext = _gettype($tbl);
$sth = $dbh->prepare("SELECT * from $tbl where panelid in ($panelid)" ); # prepare the query
# in der Schleife werden die einzelnen inserts direkt in die Datei geschrieben, geht schneller als wenn man die inserts sammelt und dann erst schreibt
$sth->execute() ; # execute the query with parameter
$max = $sth->rows;
# Holen der Daten
while (my $d = $sth->fetchrow_hashref) { # retrieve one row
$cnt += 1;
if ( $len == 0 ) { # bei 0 wird ein neues Create statement erzeugt
append_file($datei, $inserttext );
}
$text = "\n("; # Klammer für insert erstellen
$text .= _getinsert( $d, $tbl);
$len += length($text); # zählen der Länge der inserts es werden auch die , _binary
$text =~ s/,$//; # letzes , insert entfernen
$text .= "),"; # und Klammer wieder schließen
if ( $cnt == $max or ($len > $maxlength and $maxlength != 0 ) ) { # wenn maximale Länge eines insert oder Ende der Tabelle erreicht , gegen ; tauschen und Zähler auf 0
$len = 0;
$text =~ s/,$/;\n/;
}
append_file($datei, $text );
print "$cnt - $max\r";
}
}
print " ---> $tbl ready\n";
write_file($datei2, '' );
# Insert Kopf erstellen
######################################################################
$cnt = 0;
$len = 0; # Zähler für die maximale Länge in Bytes eines Insert
$tbl = 'prv_bndlmaster';
$inserttext = _gettype($tbl);
my $startbndid = $Config->{prv}->{lastbndid};
$sth = $dbh->prepare("SELECT * from $tbl where bndlid > $startbndid order by bndlid limit 10000"); # prepare the query
# in der Schleife werden die einzelnen inserts direkt in die Datei geschrieben, geht schneller als wenn man die inserts sammelt und dann erst schreibt
$sth->execute(); # execute the query with parameter
$max = $sth->rows;
# Holen der Daten
while (my $d = $sth->fetchrow_hashref) { # retrieve one row
$cnt += 1;
push @bndids, $d->{bndlid};
$Config->{prv}->{lastbndid} = $d->{bndlid};
if ( $len == 0 ) { # bei 0 wird ein neues Create statement erzeugt
append_file($datei2, $inserttext );
}
$text = "\n("; # Klammer für insert erstellen
$text .= _getinsert( $d, $tbl);
$len += length($text); # zählen der Länge der inserts es werden auch die , _binary
$text =~ s/,$//; # letzes , insert entfernen
$text .= "),"; # und Klammer wieder schließen
if ( $cnt == $max or ($len > $maxlength and $maxlength != 0 ) ) { # wenn maximale Länge eines insert oder Ende der Tabelle erreicht , gegen ; tauschen und Zähler auf 0
$len = 0;
$text =~ s/,$/;\n/;
}
append_file($datei2, $text );
print "$cnt - $max\r";
}
print " ---> $tbl ready\n";
###########################################################################
$cnt = 0;
$len = 0; # Zähler für die maximale Länge in Bytes eines Insert
$tbl = "prv_bndl";
$inserttext = _gettype($tbl);
my $bndid = join(',' , @bndids);
if ( $bndid ne '' ) {
$sth = $dbh->prepare("SELECT * from $tbl where bndlid in ($bndid)" ); # prepare the query
# in der Schleife werden die einzelnen inserts direkt in die Datei geschrieben, geht schneller als wenn man die inserts sammelt und dann erst schreibt
$sth->execute() ; # execute the query with parameter
$max = $sth->rows;
# Holen der Daten
while (my $d = $sth->fetchrow_hashref) { # retrieve one row
$cnt += 1;
if ( $len == 0 ) { # bei 0 wird ein neues Create statement erzeugt
append_file($datei2, $inserttext );
}
$text = "\n("; # Klammer für insert erstellen
$text .= _getinsert( $d, $tbl);
$len += length($text); # zählen der Länge der inserts es werden auch die , _binary
$text =~ s/,$//; # letzes , insert entfernen
$text .= "),"; # und Klammer wieder schließen
if ( $cnt == $max or ($len > $maxlength and $maxlength != 0 ) ) { # wenn maximale Länge eines insert oder Ende der Tabelle erreicht , gegen ; tauschen und Zähler auf 0
$len = 0;
$text =~ s/,$/;\n/;
}
append_file($datei2, $text );
print "$cnt - $max\r";
}
}
print " ---> $tbl ready\n";
rename 'temp.sql', 'WIDs - '.($startwid+1).'-'.$Config->{prv}->{lastwid}.'.sql';
rename 'temp2.sql', 'Bundel - '.($startbndid+1).'-'.$Config->{prv}->{lastbndid}.'.sql';
$Config->write( 'prvbackup.ini', 'utf8' );
print "\nnext\n\n";
}
$dbh->disconnect;
1;
+222
View File
@@ -0,0 +1,222 @@
#!/usr/bin/perl -w
use strict;
use warnings;
use DBI;
use Data::Dumper;
use JSON;
use Getopt::Long;
use File::Slurp qw(:std);
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
use POSIX qw(strftime);
use IO::Handle;
use File::Path qw(make_path);
STDOUT->autoflush(1);
#https://www.easysoft.com/developer/languages/perl/dbd_odbc_tutorial_part_2.html
# use Term::ANSIColor;
my $db = ""; # Datenbank
my $user = ""; # Datenbankuser
my $pass = ""; # Datenbankpasswort
my $server = ""; # Datenbankserver
my $zip = "0"; #komprimieren und oder löschen
my $maxlength = 0;
my $list = "";
my $dateien = "1";
my $rem = "0";
my %h = ('db' => \$db, 'user' => \$user, 'pass' => \$pass, 'server' => \$server, 'zip' => \$zip, 'rem' => \$rem, 'max' => \$maxlength, 'list' => \$list, 'files' => \$dateien);
GetOptions (\%h, 'db=s', 'user=s', 'pass=s', 'server=s', 'zip=s', 'rem=s', 'max=s', 'list=s', 'files=s');
if ( $db eq "" || $user eq "" || $user eq "" || $server eq "" ) {
print "\nWillkommen zum Backup einer Mysqldatenbank\n";
print "es fehlen noch folgende Parameter damit es losgehen kann.\n";
print "\n";
print "--server -s = Datenbankserver\n" if ($server eq "");
print "--db -d = Datenbankname\n" if ($db eq "");
print "--user -u = Datenbankuser\n" if ($user eq "");
print "--pass -p = Datenbankpasswort\n" if ($pass eq "");
print "--max -m = maximale Insertlänge in Bytes (optional)\n";
print "--list -l = Liste der Tabellen mit ' ' getrennt (optional)\n";
print "--files -f = 1 für jede Tabelle in eine Datei (optional)\n";
print "--zip -z = 1 zum packen, 2 packen und Sql Dateien löschen (optional) \n";
print "--rem -r = 0 vorhande Tabelle vorher löschen \n";
exit;
}
my $tref; # dient zur analyse welcher Datentyp die Spalte hat
my $text; # wird mit den Daten zum schreiben in die datei gefüllt
my @files;
my %tabellen;
my $dbh = DBI->connect("DBI:mysql:$db:$server", $user, $pass) or die "Couldn't connect to database: " . DBI->errstr;
print "Get tables from Database $db\n";
my $s1 = $dbh->selectall_arrayref("SHOW FULL TABLES FROM $db;", { Slice => {} });
# Ordner erstellen wenn nicht bekannt
if (!-d "$db") {
make_path "$db";
}
if ( $list ne "" ) {
if ( $list !~ / / ) {
$tabellen{$list} = 1;
}
}
for my $l ( split( ' ', $list ) ) {
$tabellen{$l} = 1;
}
if ( $dateien eq '0' ) {
push @files, "$server/$db/$db.sql";
}
my $firsttableend = 0;
for my $tab ( @{$s1} ) {
my $n = $tab->{"Tables_in_$db"};
my $datei = "$db/$n.sql";
if ( $dateien eq '0' ) {
$datei = "$$db/$db.sql";
} else {
write_file($datei, '' );
}
if ( $list ne "" ) {
next if ( !$tabellen{$n} );
}
$text = "\n/*!40101 SET \@OLD_CHARACTER_SET_CLIENT=@\@CHARACTER_SET_CLIENT */;\n/*!40101 SET NAMES utf8 */;\n/*!50503 SET NAMES utf8mb4 */;\n/*!40014 SET \@OLD_FOREIGN_KEY_CHECKS=@\@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n/*!40101 SET \@OLD_SQL_MODE=@\@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\n\n";
my $create = $dbh->selectrow_hashref("SHOW CREATE TABLE $db.$n" , { Slice => {} });
if ( $rem eq "1" ) {
$text .= "DROP TABLE IF EXISTS `$n`;\n";
}
# Createstatement beschaffen
$text .= $create->{'Create Table'};
$text =~ s/CREATE TABLE/CREATE TABLE IF NOT EXISTS/g;
my $s2 = $dbh->selectall_arrayref("DESCRIBE $db.$n" , { Slice => {} });
my @tabelle;
# hier wird sich der Datentyp einer Spalte gemerkt
# und ein Array mit den Spaltenamen
for my $s ( @{$s2} ) {
my $f = $s->{Field};
$tref->{ $n }->{$f} = $s->{Type};
push @tabelle, $s->{Field};
}
$text .= ";\n\n/*!40000 ALTER TABLE `$n` DISABLE KEYS */;\n";
if ( $firsttableend == 1 ) {
append_file($datei, $text );
} else {
write_file($datei, $text );
}
# Insert Kopf erstellen
my $inserttext .= "INSERT INTO $n (";
for my $col( @tabelle ) {
$inserttext .= "`".$col."`,"
}
$inserttext =~ s/,$/) VALUES/;
print "create Inserts for $n\n";
my $cnt = 0;
my $len = 0; # Zähler für die maximale Länge in Bytes eines Insert
my $sth = $dbh->prepare("SELECT * from $db.$n"); # prepare the query
# in der Schleife werden die einzelnen inserts direkt in die Datei geschrieben, geht schneller als wenn man die inserts sammelt und dann erst schreibt
$sth->execute(); # execute the query with parameter
my $max = $sth->rows;
# Holen der Daten
while (my $d = $sth->fetchrow_hashref) { # retrieve one row
$cnt += 1;
if ( $len == 0 ) { # bei 0 wird ein neues Create statement erzeugt
append_file($datei, $inserttext );
}
$text = "\n("; # Klammer für insert erstellen
# hier wird entschieden wie die einzelnen Daten in abhängigkeit des Datentyps geschrieben werden
# es kommen die gemerkten Spalten (@tabelle) und Datentypen ($tref) zum Einsatz
# zb: mit Strings mit '' integer ohne '', umgang mit zeilenumbrüchen, blobs
# bei einem unbekannten typ kommt der Dumper
for my $col( @tabelle ) {
if ( defined $d->{$col} ) {
if ( $tref->{ $n }->{$col} =~ /int|year|double|decimal|float/ ) {
$text .= $d->{$col}.","
} elsif ($tref->{ $n }->{$col} =~ /char|date|time|enum|text/ ) {
$d->{$col} =~ s/\\/\\\\/g;
$d->{$col} =~ s/\n/\\n/g;
$d->{$col} =~ s/\r/\\n/g;
$d->{$col} =~ s/\r\n\\/\\n/g;
$d->{$col} =~ s/\'/\\'/g;
$text .= "'".$d->{$col}."',"
} elsif ($tref->{ $n }->{$col} =~ /blob/ ) {
$text .= "_binary 0x". uc unpack("H*",$d->{$col}).",";
} else {
print Dumper($tref->{ $n }->{$col});
}
} else {
$text .= "NULL,";
}
}
$len += length($text); # zählen der Länge der inserts es werden auch die , _binary
$text =~ s/,$//; # letzes , insert entfernen
$text .= "),"; # und Klammer wieder schließen
if ( $cnt == $max or ($len > $maxlength and $maxlength != 0 ) ) { # wenn maximale Länge eines insert oder Ende der Tabelle erreicht , gegen ; tauschen und Zähler auf 0
$len = 0;
$text =~ s/,$/;\n/;
}
append_file($datei, $text );
print "$cnt - $max\r";
}
print " ---> ready\n";
$text = "/*!40000 ALTER TABLE `$n` ENABLE KEYS */;\n\n/*!40101 SET SQL_MODE=IFNULL(\@OLD_SQL_MODE, '') */;\n/*!40014 SET FOREIGN_KEY_CHECKS=IF(\@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, \@OLD_FOREIGN_KEY_CHECKS) */;\n/*!40101 SET CHARACTER_SET_CLIENT=\@OLD_CHARACTER_SET_CLIENT */;\n";
append_file($datei, $text );
if ( $dateien == 1 ) {
push @files, "$db/$n.sql";
}
$firsttableend = 1;
}
$dbh->disconnect;
if ( $zip > 0 ) {
print "Compress $db into zip file ";
my $now_string = strftime "%Y-%m-%d %H.%M", localtime;
# Creating a new zip file
my $zip = Archive::Zip->new();
my $zipfile = "$db-$now_string.zip";
# Trying to read the existing zip structure, when zip archive already exists
$zip->read( $zipfile ) if -s $zipfile;
foreach my $file ( @files ) {
# remove if the current file was already in the zip:
$zip->removeMember( $file );
# add a new file to zip object in memory, using best compressionLevel = 9
$zip->addFile( $file, $file, 5 );
}
if ( $zip->numberOfMembers ) {
# Save to a zip file $zipfile
$zip->overwriteAs( $zipfile );
}
if ( $zip > 1 ) {
unlink @files;
}
print "---> ready\n";
}
1;
+24
View File
@@ -0,0 +1,24 @@
./sqlbackup.pl -s dbs-ats -u atsrw -p ats4MLs -d ats -m 1024000 -f 0;
./sqlbackup.pl -s dbs-misc1 -u audit -p jeju4audit -d audit -m 1024000 -f 0;
./sqlbackup.pl -s dbs-koma -u komarw -p komaher -d koma -m 1024000 -f 0;
./sqlbackup.pl -s dbsetv -u etv -p 'TS(1254)' -d etv -m 1024000;
./sqlbackup.pl -s dbsetv -u etv -p 'TS(1254)' -d gebman -m 1024000;
./sqlbackup.pl -s dbsetv -u etv -p 'TS(1254)' -d aoiv -m 1024000;
./sqlbackup.pl -s dbsetv -u etv -p 'TS(1254)' -d epmg -m 1024000;
./sqlbackup.pl -s dbsetv -u etv -p 'TS(1254)' -d bgv -m 1024000;
./sqlbackup.pl -s dbsetv -u etv -p 'TS(1254)' -d pgw -m 1024000;
./sqlbackup.pl -s zeus -u prod-ro -p '' -d prod -m 1024000 -l 'kd2_mls_kst kd2_mls_hersteller kd2_fermon_steuerer kd2_fermon_platzinfo kd2_fermon_platzgrp kd2_fermon_auftr_text kd2_fermon_auftr_sperrtext kd2_fermon_auftr kd2_fermon_arbpl_prio kd2_fermon_arbpl kd2_fermon_analyse kd2_mls_lieferanten kd2_mls_kdnstamm kd2_mls_inventar suas_assessment_category suas_assessment_event suas_category_group suas_category_groupmember suas_group_entry suas_rating_period_start suas_tt_mt';
./sqlbackup.pl -s cga -u kvasir-adm -p 'KVa51r-20!8' -d kvasir -m 1024000 -f 0;
perl sqlbackup.pl -r 1 -s dbs-misc1 -u audit -p jeju4audit -d audit -m 1024000 -f 0
perl sqlbackup.pl -r 1 -s dbs-koma -u komarw -p komaher -d koma -m 1024000 -f 0
perl sqlbackup.pl -r 1 -s dbsetv -u etv -p "TS(1254)" -d etv -m 1024000
perl sqlbackup.pl -r 1 -s dbsetv -u etv -p "TS(1254)" -d gebman -m 1024000
perl sqlbackup.pl -r 1 -s dbsetv -u etv -p "TS(1254)" -d aoiv -m 1024000
perl sqlbackup.pl -r 1 -s dbsetv -u etv -p "TS(1254)" -d epmg -m 1024000
perl sqlbackup.pl -r 1 -s dbsetv -u etv -p "TS(1254)" -d bgv -m 1024000
perl sqlbackup.pl -r 1 -s dbsetv -u etv -p "TS(1254)" -d pgw -m 1024000
perl sqlbackup.pl -r 1 -s zeus -u prod-ro -p "" -d prod -m 1024000 -l "kd2_mls_kst kd2_mls_hersteller kd2_fermon_steuerer kd2_fermon_platzinfo kd2_fermon_platzgrp kd2_fermon_auftr_text kd2_fermon_auftr_sperrtext kd2_fermon_auftr kd2_fermon_arbpl_prio kd2_fermon_arbpl kd2_fermon_analyse kd2_mls_lieferanten kd2_mls_kdnstamm kd2_mls_inventar suas_assessment_category suas_assessment_event suas_category_group suas_category_groupmember suas_group_entry suas_rating_period_start suas_tt_mt"
perl sqlbackup.pl -r 1 -s cga -u kvasir-adm -p "KVa51r-20!8" -d kvasir -m 1024000 -f 0
perl sqlbackup.pl -r 1 -s jupiter -u prv19 -p "!nd!4n3R" -d prod -m 1024000 -l "prvx_cnr_msa prvx_cnr_msa_me prvx_cnr_pca prvx_cnr_pca_me prvx_cnr_testplan prvx_pv_packorder prvx_qscdata prvx_sfs_eswareinmal prvx_sob_custorder prvx_sob_progdata prvx_vec_cert prvx_vss_data prv_ack2sap prv_ack2sap_log prv_addr prv_addrpool prv_addrtype prv_cfg_usage prv_conf prv_cpscan prv_customer prv_dpnd prv_dpndmaster prv_exec prv_execnote prv_iavcomp prv_log prv_macpool prv_park prv_parkpool prv_phase prv_product prv_station prv_tag prv_xbin prv_zinf prv_zval prv_zzval"
+4
View File
@@ -0,0 +1,4 @@
(1093627,790906,'2006-03-27 09:13:29',4,37,1,0,0,0,0,0,0,0,0),
(1093670,790906,'2006-03-27 09:25:17',5,39,1,0,0,0,0,0,0,0,0),
(1074145,790907,'2006-03-08 11:25:35',1,1,1,0,0,0,0,0,0,0,0),
+141
View File
@@ -0,0 +1,141 @@
package Nicehashapi;
use Moo;
use strictures 2;
use namespace::clean;
use File::Slurp;
use Data::Printer;
use Mojo::UserAgent;
use Digest::SHA qw(hmac_sha256_hex);;
use UUID::Tiny ':std';
use Time::HiRes qw(gettimeofday);
use Encode qw(decode encode);
use Data::Dumper;
has key => (
is => 'ro',
);
has secret => (
is => 'ro',
);
has organisation_id => (
is => 'ro',
);
# my $key = '8bcbda58-5a26-4ce4-8e61-3a0fd894cfbb';
# my $secret = '59dc1ee5-a0e6-4ba6-9a9c-a043c350b88b84266786-2d14-4b9f-9ae5-d168ed8376b7';
# my $organisation_id = '4c615374-bf85-42fd-860d-b1bf4568c01f';
sub get_payouts {
my ( $self, $page, $size) = @_;
return _request($self, 'GET', '/main/api/v2/mining/rigs/payouts', "page=$page&size=$size", undef);
}
sub get_currencies {
my ( $self) = @_;
return _request($self, 'GET', '/main/api/v2/public/currencies/', '', undef);
}
sub get_prices {
my ( $self) = @_;
return _request($self, 'GET', '/exchange/api/v2/info/prices', '', undef);
}
sub get_hashpowerEarnings {
my ( $self, $currencies) = @_;
return _request($self, 'GET', '/main/api/v2/accounting/hashpowerEarnings/' . $currencies, '', undef);
}
sub get_myOrders {
my ( $self) = @_;
return _request($self, 'GET', '/exchange/api/v2/info/myOrders', '', undef);
}
sub get_accounts2 {
my ( $self, $extendedResponse, $fiat) = @_;
return _request($self, 'GET', '/main/api/v2/accounting/accounts2', "extendedResponse=$extendedResponse&fiat=$fiat", undef);
}
sub get_accounting_activity {
my ( $self, $currency, $type, $stage, $limit ) = @_;
my $query;
if ( defined $limit ) {
$query = "limit=$limit";
}
if ( defined $type ) {
$query .= "&type=$type";
}
if ( defined $stage ) {
$query .= "&stage=$stage";
}
return _request($self, 'GET', '/main/api/v2/accounting/activity/'.$currency, $query, undef);
# return _request($self, 'GET', '/main/api/v2/accounting/activity/'.$currency, '' , undef);
}
sub _request {
my ( $self, $method, $path, $query, $body) = @_;
my $xtime = int (gettimeofday * 1000);
my $xnonce = create_uuid(UUID_V4);
my $uid = uuid_to_string($xnonce);
my $xnonce2 = create_uuid(UUID_V4);
my $uid2 = uuid_to_string($xnonce);
my $message = encode('UTF-8', $self->key);
$message .= encode('UTF-8', chr(0x00));
$message .= encode('UTF-8',$xtime);
$message .= encode('UTF-8',chr(0x00));
$message .= encode('UTF-8',$uid);
$message .= encode('UTF-8',chr(0x00));
$message .= encode('UTF-8',chr(0x00));
$message .= encode('UTF-8', $self->organisation_id);
$message .= encode('UTF-8',chr(0x00));
$message .= encode('UTF-8',chr(0x00));
$message .= encode('UTF-8',$method);
$message .= encode('UTF-8',chr(0x00));
$message .= encode('UTF-8',$path);
$message .= encode('UTF-8',chr(0x00));
$message .= encode('UTF-8',$query);
if ($body) {
my $body_json = Dumper($body);
$message .= encode('UTF-8',chr(0x00));
$message .= encode('UTF-8', $body_json);
}
my $digest = hmac_sha256_hex($message, $self->secret);
my $ua = Mojo::UserAgent->new();
my $headers = {
'X-Time' => $xtime,
'X-Nonce'=> $uid,
'X-Auth'=> $self->key . ':' . $digest ,
'Content-Type'=> 'application/json',
'X-Organization-Id'=> $self->organisation_id,
'X-Request-Id'=> $uid2
};
if ( $query ) {
$query = '?'.$query;
}
my $data = $ua->get('https://api2.nicehash.com' . $path.$query => $headers )->res;
if ( $path =~ /activity/ ) {
p $data;
print $path.$query."\n";
}
# my $data = $ua->get('https://api2.nicehash.com' . $path.$query => $headers )->res->json;
return $data->json;
}
1;
File diff suppressed because it is too large. Load diff
+77
View File
@@ -0,0 +1,77 @@
buy ;value ;sell ;value ;date ;how ;fee ;value ;ineuro ;
BTC ;0.00111388 ;EUR ;50 ;2021-02-17 21:24:00 ;ste ;EUR ;1.45 ;43586.38 ;
ETH ;0.01677347 ;BTC ;0.00059096 ;2021-02-17 21:26:42 ;ste ;ETH ;0.00008387 ;1473.42 ;
RVN ;67.56756757 ;BTC ;0.0001 ;2021-02-17 21:51:55 ;ste ;RVN ;0.33783784 ;0.06517260032601803;
LTC ;0.05581514 ;BTC ;0.00024548 ;2021-02-18 16:14:00 ;ste ;LTC ;0.00027908 ;196.39130990886653 ;
BTC ;0.00342421 ;EUR ;150 ;2021-02-18 16:14:00 ;ste ;EUR ;2.18 ;43169.08 ;
XRP ;24.084778 ;BTC ;0.00025 ;2021-02-18 22:50:28 ;ste ;XRP ;0.120424 ;0.4454225873823748 ;
POLY ;37.90087464 ;BTC ;0.00026 ;2021-02-18 22:53:37 ;ste ;POLY ;0.18950437 ;0.16528781250821772;
RVN ;77.34806630 ;BTC ;0.00014 ;2021-02-18 23:09:21 ;ste ;RVN ;0.38674033 ;0.06149183018139609;
XLM ;25.8799172 ;BTC ;0.00025 ;2021-02-18 23:12:00 ;ste ;XLM ;0.1293996 ;0.4126191293430188 ;
ETH ;0.01870189 ;BTC ;0.0007 ;2021-02-18 23:22:00 ;ste ;ETH ;0.00009351 ;1532.245300670433 ;
MATIC ;66.00660066 ;BTC ;0.0002 ;2021-02-21 17:45:00 ;ste ;MATIC ;0.330033 ;0.12043422966095804;
TNT ;101.01010101 ;BTC ;0.0001 ;2021-02-21 17:33:00 ;ste ;TNT ;0.50505051 ;0.0495 ;
BTC ;0.00122211 ;EUR ;50 ;2021-03-01 13:28:00 ;ste ;EUR ;1.45 ;39726.37 ;
ETH ;0.04078763 ;BTC ;0.0013 ;2021-03-01 13:33:05 ;ste ;ETH ;0.00020394 ;1225.86 ;
BTC ;0.00307542 ;EUR ;150 ;2021-03-11 22:59:00 ;hen ;EUR ;2.18 ;48064.98 ;
BTC ;0.00222725 ;EUR ;100 ;2021-03-25 22:00:00 ;ste ;EUR ;1.45 ;44247.39 ;
FTM ;27.24795640 ;BTC ;0.0002 ;2021-04-02 10:02:00 ;ste ;FTM ;0.13623978 ;0.3769306838590017 ;
BTC ;0.00195425 ;EUR ;100 ;2021-04-12 19:33:00 ;ste ;EUR ;1.45 ;50428.55 ;
ETH ;0.05622319 ;BTC ;0.002 ;2021-04-12 19:34:05 ;ste ;ETH ;0.00028112 ;1806.414093543639 ;
BTC ;0.00210390 ;EUR ;100 ;2021-04-19 19:25:00 ;ste ;EUR ;1.45 ;46841.58 ;
BTC ;0.00236794 ;EUR ;100 ;2021-04-25 19:25:00 ;ste ;EUR ;1.45 ;42230.79 ;
ETH ;0.03071291 ;BTC ;0.0022 ;2021-05-10 23:52:24 ;ste ;ETH ;0.00015356 ;3308.70 ;
BTC ;0.00472456 ;EUR ;200 ;2021-05-13 14:18:00 ;ste ;EUR ;2.90 ;41718.17 ;
LBA ;1846.15384615 ;BTC ;0.00024 ;2021-05-14 17:12:00 ;ste ;LBA ;9.23076923 ;0.00544389 ;
DOGE ;111.88983856 ;BTC ;0.0011782 ;2021-05-14 17:25:00 ;ste ;DOGE ;0.55944919 ;0.44686811 ;
BTC ;0.00524624 ;EUR ;200 ;2021-05-18 08:22:00 ;ste ;EUR ;2.90 ;37569.76 ;
AOA ;4007.14285714 ;BTC ;0.0002805 ;2021-05-18 18:42:12 ;ste ;AOA ;20.03571429 ;0.00249554 ;
ETH ;0.03566481 ;BTC ;0.0028006 ;2021-05-18 19:56:40 ;ste ;ETH ;0.00017832 ;2817.97 ;
BTC ;0.00596527 ;EUR ;200 ;2021-05-20 22:47:00 ;ste ;EUR ;2.90 ;33041.25 ;
ETH ;0.04406291 ;BTC ;0.0030403 ;2021-05-20 23:07:13 ;ste ;EUR ;0.00022031 ;2269.48 ;
KEY ;2303.48631882 ;BTC ;0.0005989 ;2021-05-20 23:38:00 ;ste ;KEY ;11.5174316 ;0.0089 ;
MITH ;477.01929598 ;BTC ;0.0005984 ;2021-05-20 23:45:09 ;ste ;MITH ;2.38509648 ;0.04213771 ;
BTC ;0.00630013 ;EUR ;200 ;2021-05-24 16:22:00 ;ste ;EUR ;2.90 ;31285.07 ;
RVN ;162.12121212 ;BTC ;0.000321 ;2021-05-24 16:25:00 ;ste ;RVN ;0.81060606 ;0.06168224 ;
FTM ;37.80918728 ;BTC ;0.000321 ;2021-05-24 16:28:00 ;ste ;FTM ;0.18904594 ;0.264448598 ;
EUR ;55.81 ;BTC ;0.002 ;2021-05-29 23:13:00 ;ste ;BTC ;0.00004244 ; ;Binance
OCEAN ;43.46733668 ;BTC ;0.0006055 ;2021-06-16 23:34:00 ;ste ;OCEAN ;0.21733668 ;0.46011561 ;
BTC ;0.00596527 ;EUR ;200 ;2021-06-20 21:47:00 ;ste ;EUR ;2.90 ;33527.40 ;
XRP ;18.679522 ;BTC ;0.0003612 ;2021-06-25 15:15:16 ;ste ;XRP ;0.093867 ;0.53534560 ;
POLY ;82.24118993 ;BTC ;0.0003612 ;2021-06-25 15:16:14 ;ste ;POLY ;0.41327231 ;0.12159357 ;
MITH ;326.46756757 ;BTC ;0.0003642 ;2021-06-25 15:17:49 ;ste ;MITH ;1.64054054 ;0.03063091 ;
FTM ;109.82689394 ;BTC ;0.0007285 ;2021-06-25 15:18:43 ;ste ;FTM ;0.55189394 ;0.18210476 ;
RVN ;696.94647436 ;BTC ;0.0010927 ;2021-06-25 15:17:04 ;ste ;RVN ;3.50224359 ;0.04304491 ;
BTC ;0.00677037 ;EUR ;200 ;2021-06-28 21:35:00 ;ste ;EUR ;2.90 ;29540.48 ;
LOOM ;243.45744680 ;BTC ;0.000345 ;2021-06-25 32:35:04 ;ste ;LOOM ;1.22340426 ;0.04107493 ;
SNT ;239.07638889 ;BTC ;0.0010927 ;2021-06-25 15:17:04 ;ste ;SNT ;1.20138889 ;0.04182763 ;
ETH ;0.04937313 ;BTC ;0.003403 ;2021-07-07 15:52:04 ;ste ;ETH ;0.00024811 ;2025.39316 ;
ETH ;0.06136540 ;BTC ;0.003731 ;2021-07-21 15:41:07 ;ste ;ETH ;0.00030837 ;1629.58279 ;
KEY ;1767.30952381 ;BTC ;0.000373 ;2021-07-21 15:50:00 ;ste ;KEY ;8.88095238 ;0.00565831 ;
LBA ;4643.85 ;BTC ;0.000373 ;2021-07-21 15:53:38 ;ste ;LBA ;18.65 ;0.00215338 ;
BTC ;0.00601832 ;EUR ;200 ;2021-07-26 14:15:00 ;ste ;EUR ;2.90 ;33231.86 ;
ETH ;0.10033165 ;BTC ;0.00613 ;2021-07-26 14:14:12 ;ste ;ETH ;0.00040294 ;1993.38892 ;
EUR ;99.51 ;BTC ;0.002967 ;2021-05-29 23:13:00 ;ste ;BTC ;0 ; ;Coinbase
EUR ;50.11 ;BTC ;0.001541 ;2021-08-03 13:37:00 ;ste ;BTC ;0.000001 ; ;Binance
EUR ;50 ;BTC ;0.001485 ;2021-08-04 23:57:00 ;ste ;BTC ;0.000001 ; ;freebitco.in
BTC ;0.00496098 ;EUR ;200 ;2021-08-11 19:44:00 ;ste ;EUR ;2.90 ;40314.61 ;
BTC ;0.00190101 ;RVN ;604 ;2021-08-12 16:25:17 ;ste ;BTC ;0.00000763 ; ;71.96
EUR ;50.02 ;BTC ;0.001274 ;2021-08-13 11:20:00 ;ste ;BTC ;0.000001 ; ;freebitco.in
ETH ;0.04705297 ;BTC ;0.00613 ;2021-08-16 22:07:34 ;ste ;ETH ;0.00018897 ;2725.86 ;
EUR ;100 ;BTC ;0.0025854 ;2021-08-18 16:47:00 ;ste ;BTC ;0.000001 ; ;Binance
XRP ;104.052804 ;BTC ;0.002477 ;2021-08-25 11:10:14 ;ste ;XRP ;0.417883 ;0.961050 ;
EUR ;100.57 ;BTC ;0.002472 ;2021-08-25 14:22:00 ;ste ;BTC ;0 ; ;Coinbase
BTC ;0.00109573 ;RVN ;398.44813612 ;2021-08-26 15:58:17 ;ste ;BTC ;0.00000438 ;sellout ;43.77
RVN ;870.69677420 ;BTC ;0.002439 ;2021-08-27 19:33:37 ;ste ;RVN ;3.49677419 ;0.11485054 ;
BTC ;0.00051639 ;LBA ;6480.77307692 ;2021-09-01 17:32:17 ;ste ;BTC ;0.00000207 ;sellout ;20.64
BTC ;0.00466603 ;EUR ;200 ;2021-09-02 13:18:00 ;ste ;EUR ;2.90 ;42915.69 ;
MITH ;269.18918919 ;BTC ;0.0003 ;2021-09-07 20:13:42 ;ste ;MITH ;1.08108108 ;0.04364959 ;
RVN ;521.36296296 ;BTC ;0.001272 ;2021-09-07 20:16:29 ;ste ;RVN ;2.09382716 ;0.09722593 ;
EUR ;140.67 ;BTC ;0.00370768 ;2021-09-13 22:07:00 ;ste ;BTC ;0.00000176 ; ;freebitco.in
BTC ;0.00538674 ;EUR ;200 ;2021-09-22 17:46:00 ;ste ;EUR ;2.86 ;37128.20 ;
BTC ;0.00560353 ;FTM ;174.5587519 ;2021-10-16 15:00:17 ;ste ;BTC ;0.0000225 ;sellout ;297.64
FTM ;41.73395974 ;BTC ;0.001873 ;2021-10-30 10:40:00 ;ste ;FTM ;0.16760626 ;2.39613 ;
RVN ;750.75376884 ;BTC ;0.0015 ;2021-11-27 13:35:55 ;ste ;RVN ;3.01507538 ;0.0959 ;
FTM ;10.34870756 ;BTC ;0.00041 ;2021-11-27 13:51:39 ;ste ;FTM ;0.04156107 ;1.9326 ;
BTC ;0.00020643 ;LTC ;0.05553606 ;2021-11-19 20:31:51 ;ste ;BTC ;0.00000083 ;sellout ;
EUR ;200.29 ;BTC ;0.00546 ;2022-01-18 21:49:00 ;ste ;BTC ;0.000005 ; ;Binance
1 buy value sell value date how fee value ineuro
2 BTC 0.00111388 EUR 50 2021-02-17 21:24:00 ste EUR 1.45 43586.38
3 ETH 0.01677347 BTC 0.00059096 2021-02-17 21:26:42 ste ETH 0.00008387 1473.42
4 RVN 67.56756757 BTC 0.0001 2021-02-17 21:51:55 ste RVN 0.33783784 0.06517260032601803
5 LTC 0.05581514 BTC 0.00024548 2021-02-18 16:14:00 ste LTC 0.00027908 196.39130990886653
6 BTC 0.00342421 EUR 150 2021-02-18 16:14:00 ste EUR 2.18 43169.08
7 XRP 24.084778 BTC 0.00025 2021-02-18 22:50:28 ste XRP 0.120424 0.4454225873823748
8 POLY 37.90087464 BTC 0.00026 2021-02-18 22:53:37 ste POLY 0.18950437 0.16528781250821772
9 RVN 77.34806630 BTC 0.00014 2021-02-18 23:09:21 ste RVN 0.38674033 0.06149183018139609
10 XLM 25.8799172 BTC 0.00025 2021-02-18 23:12:00 ste XLM 0.1293996 0.4126191293430188
11 ETH 0.01870189 BTC 0.0007 2021-02-18 23:22:00 ste ETH 0.00009351 1532.245300670433
12 MATIC 66.00660066 BTC 0.0002 2021-02-21 17:45:00 ste MATIC 0.330033 0.12043422966095804
13 TNT 101.01010101 BTC 0.0001 2021-02-21 17:33:00 ste TNT 0.50505051 0.0495
14 BTC 0.00122211 EUR 50 2021-03-01 13:28:00 ste EUR 1.45 39726.37
15 ETH 0.04078763 BTC 0.0013 2021-03-01 13:33:05 ste ETH 0.00020394 1225.86
16 BTC 0.00307542 EUR 150 2021-03-11 22:59:00 hen EUR 2.18 48064.98
17 BTC 0.00222725 EUR 100 2021-03-25 22:00:00 ste EUR 1.45 44247.39
18 FTM 27.24795640 BTC 0.0002 2021-04-02 10:02:00 ste FTM 0.13623978 0.3769306838590017
19 BTC 0.00195425 EUR 100 2021-04-12 19:33:00 ste EUR 1.45 50428.55
20 ETH 0.05622319 BTC 0.002 2021-04-12 19:34:05 ste ETH 0.00028112 1806.414093543639
21 BTC 0.00210390 EUR 100 2021-04-19 19:25:00 ste EUR 1.45 46841.58
22 BTC 0.00236794 EUR 100 2021-04-25 19:25:00 ste EUR 1.45 42230.79
23 ETH 0.03071291 BTC 0.0022 2021-05-10 23:52:24 ste ETH 0.00015356 3308.70
24 BTC 0.00472456 EUR 200 2021-05-13 14:18:00 ste EUR 2.90 41718.17
25 LBA 1846.15384615 BTC 0.00024 2021-05-14 17:12:00 ste LBA 9.23076923 0.00544389
26 DOGE 111.88983856 BTC 0.0011782 2021-05-14 17:25:00 ste DOGE 0.55944919 0.44686811
27 BTC 0.00524624 EUR 200 2021-05-18 08:22:00 ste EUR 2.90 37569.76
28 AOA 4007.14285714 BTC 0.0002805 2021-05-18 18:42:12 ste AOA 20.03571429 0.00249554
29 ETH 0.03566481 BTC 0.0028006 2021-05-18 19:56:40 ste ETH 0.00017832 2817.97
30 BTC 0.00596527 EUR 200 2021-05-20 22:47:00 ste EUR 2.90 33041.25
31 ETH 0.04406291 BTC 0.0030403 2021-05-20 23:07:13 ste EUR 0.00022031 2269.48
32 KEY 2303.48631882 BTC 0.0005989 2021-05-20 23:38:00 ste KEY 11.5174316 0.0089
33 MITH 477.01929598 BTC 0.0005984 2021-05-20 23:45:09 ste MITH 2.38509648 0.04213771
34 BTC 0.00630013 EUR 200 2021-05-24 16:22:00 ste EUR 2.90 31285.07
35 RVN 162.12121212 BTC 0.000321 2021-05-24 16:25:00 ste RVN 0.81060606 0.06168224
36 FTM 37.80918728 BTC 0.000321 2021-05-24 16:28:00 ste FTM 0.18904594 0.264448598
37 EUR 55.81 BTC 0.002 2021-05-29 23:13:00 ste BTC 0.00004244 Binance
38 OCEAN 43.46733668 BTC 0.0006055 2021-06-16 23:34:00 ste OCEAN 0.21733668 0.46011561
39 BTC 0.00596527 EUR 200 2021-06-20 21:47:00 ste EUR 2.90 33527.40
40 XRP 18.679522 BTC 0.0003612 2021-06-25 15:15:16 ste XRP 0.093867 0.53534560
41 POLY 82.24118993 BTC 0.0003612 2021-06-25 15:16:14 ste POLY 0.41327231 0.12159357
42 MITH 326.46756757 BTC 0.0003642 2021-06-25 15:17:49 ste MITH 1.64054054 0.03063091
43 FTM 109.82689394 BTC 0.0007285 2021-06-25 15:18:43 ste FTM 0.55189394 0.18210476
44 RVN 696.94647436 BTC 0.0010927 2021-06-25 15:17:04 ste RVN 3.50224359 0.04304491
45 BTC 0.00677037 EUR 200 2021-06-28 21:35:00 ste EUR 2.90 29540.48
46 LOOM 243.45744680 BTC 0.000345 2021-06-25 32:35:04 ste LOOM 1.22340426 0.04107493
47 SNT 239.07638889 BTC 0.0010927 2021-06-25 15:17:04 ste SNT 1.20138889 0.04182763
48 ETH 0.04937313 BTC 0.003403 2021-07-07 15:52:04 ste ETH 0.00024811 2025.39316
49 ETH 0.06136540 BTC 0.003731 2021-07-21 15:41:07 ste ETH 0.00030837 1629.58279
50 KEY 1767.30952381 BTC 0.000373 2021-07-21 15:50:00 ste KEY 8.88095238 0.00565831
51 LBA 4643.85 BTC 0.000373 2021-07-21 15:53:38 ste LBA 18.65 0.00215338
52 BTC 0.00601832 EUR 200 2021-07-26 14:15:00 ste EUR 2.90 33231.86
53 ETH 0.10033165 BTC 0.00613 2021-07-26 14:14:12 ste ETH 0.00040294 1993.38892
54 EUR 99.51 BTC 0.002967 2021-05-29 23:13:00 ste BTC 0 Coinbase
55 EUR 50.11 BTC 0.001541 2021-08-03 13:37:00 ste BTC 0.000001 Binance
56 EUR 50 BTC 0.001485 2021-08-04 23:57:00 ste BTC 0.000001 freebitco.in
57 BTC 0.00496098 EUR 200 2021-08-11 19:44:00 ste EUR 2.90 40314.61
58 BTC 0.00190101 RVN 604 2021-08-12 16:25:17 ste BTC 0.00000763 71.96
59 EUR 50.02 BTC 0.001274 2021-08-13 11:20:00 ste BTC 0.000001 freebitco.in
60 ETH 0.04705297 BTC 0.00613 2021-08-16 22:07:34 ste ETH 0.00018897 2725.86
61 EUR 100 BTC 0.0025854 2021-08-18 16:47:00 ste BTC 0.000001 Binance
62 XRP 104.052804 BTC 0.002477 2021-08-25 11:10:14 ste XRP 0.417883 0.961050
63 EUR 100.57 BTC 0.002472 2021-08-25 14:22:00 ste BTC 0 Coinbase
64 BTC 0.00109573 RVN 398.44813612 2021-08-26 15:58:17 ste BTC 0.00000438 sellout 43.77
65 RVN 870.69677420 BTC 0.002439 2021-08-27 19:33:37 ste RVN 3.49677419 0.11485054
66 BTC 0.00051639 LBA 6480.77307692 2021-09-01 17:32:17 ste BTC 0.00000207 sellout 20.64
67 BTC 0.00466603 EUR 200 2021-09-02 13:18:00 ste EUR 2.90 42915.69
68 MITH 269.18918919 BTC 0.0003 2021-09-07 20:13:42 ste MITH 1.08108108 0.04364959
69 RVN 521.36296296 BTC 0.001272 2021-09-07 20:16:29 ste RVN 2.09382716 0.09722593
70 EUR 140.67 BTC 0.00370768 2021-09-13 22:07:00 ste BTC 0.00000176 freebitco.in
71 BTC 0.00538674 EUR 200 2021-09-22 17:46:00 ste EUR 2.86 37128.20
72 BTC 0.00560353 FTM 174.5587519 2021-10-16 15:00:17 ste BTC 0.0000225 sellout 297.64
73 FTM 41.73395974 BTC 0.001873 2021-10-30 10:40:00 ste FTM 0.16760626 2.39613
74 RVN 750.75376884 BTC 0.0015 2021-11-27 13:35:55 ste RVN 3.01507538 0.0959
75 FTM 10.34870756 BTC 0.00041 2021-11-27 13:51:39 ste FTM 0.04156107 1.9326
76 BTC 0.00020643 LTC 0.05553606 2021-11-19 20:31:51 ste BTC 0.00000083 sellout
77 EUR 200.29 BTC 0.00546 2022-01-18 21:49:00 ste BTC 0.000005 Binance
+206
View File
@@ -0,0 +1,206 @@
use lib '/home/steffen/scripte/nicehash';
use Nicehashapi;
use Data::Printer;
use File::Slurp;
use Mojo::UserAgent;
use Time::Piece;
# use Term::ANSIColor;
use File::Copy;
my $einsatzhenner = 150;
my $api = Nicehashapi->new(
key => '8bcbda58-5a26-4ce4-8e61-3a0fd894cfbb',
secret => '59dc1ee5-a0e6-4ba6-9a9c-a043c350b88b84266786-2d14-4b9f-9ae5-d168ed8376b7',
organisation_id => '4c615374-bf85-42fd-860d-b1bf4568c01f'
);
my $data = $api->get_payouts(0, 10_000);
my @trading = read_file('/home/steffen/scripte/nicehash/investment.csv');
my %washabich;
my %washabichwoanders;
my %avgineuro;
my %count4avgineuro;
# my %kleinstekurse = {
# ""
# }
for my $l ( @trading ) {
next if ( $l =~ /^buy/ );
chomp $l;
$l = $l =~ s/\s//gr;
my @sp = split(/;/, $l );
if ( $sp[0] eq 'BTC' && $sp[2] eq 'EUR' ) {
$washabich{'EUR'} += $sp[3] ;
$washabich{$sp[0]} += ($sp[1] * $sp[8] );
$avgineuro{$sp[0]} += $sp[8];
$count4avgineuro{$sp[0]} += 1;
} elsif ( $sp[0] eq 'BTC' && $sp[2] ne 'EUR' ) {
if ( $sp[8] eq 'sellout' ) {
$avgineuro{$sp[2]} = 0;
$count4avgineuro{$sp[2]} = 0;
$washabich{$sp[2]} = 0;
} else {
$washabich{$sp[2]} -= (($sp[1]- $sp[7] ) * $sp[8] );
}
} elsif ( $sp[0] eq 'EUR' ) {
$washabich{'EUR'} -= $sp[1];
$washabichwoanders{$sp[9]} += $sp[1];
} else {
$washabich{$sp[0]} += (($sp[1]- $sp[7] ) * $sp[8] );
$avgineuro{$sp[0]} += $sp[8];
$count4avgineuro{$sp[0]} += 1;
$washabich{'BTC'} -= (($sp[1]- $sp[7] ) * $sp[8] );
}
}
p $count4avgineuro{'FTM'};
p $washabich{'FTM'};
for my $k ( keys %avgineuro ) {
next if ( $count4avgineuro{$k} == 0 );
$avgineuro{$k} = $avgineuro{$k} / $count4avgineuro{$k};
}
$washabich{'EUR'} = $washabich{'EUR'} - $einsatzhenner;
my $get_accounts2 = $api->get_accounts2('true', 'EUR');
my %btcwerte;
my %curwerte;
for my $li (@{$get_accounts2->{currencies}}) {
if ( $li->{totalBalance} > 0 ) {
$btcwerte{$li->{currency}} = $li->{fiatRate};
$curwerte{$li->{currency}} = $li->{totalBalance};
}
}
my $othercurrbtc = $maxbtc - $btcwerte{'BTC'};
my $cur = $api->get_prices;
my $gesamtgebuehr = 0;
my $gesamt = 0;
# write_file('/mnt/h/Download/nicehashmining.csv', "Type,Buy Amount,Buy Currency,Sell Amount,Sell Currency,Fee,Fee Currency,Exchange,Trade-Group,Comment,Date\n");
my $min;
my $max;
# mining
for my $line (@{$data->{list}}) {
my $date = localtime($line->{created} / 1000);
if ( not defined $min ) {
$min = $line->{created};
}
if ( not defined $max ) {
$max = $line->{created};
}
if ( $min > $line->{created} ) {
$min = $line->{created};
}
if ( $max < $line->{created} ) {
$max = $line->{created};
}
my $datetime = $date->ymd .' ' . $date->hms;
my $currencies = $line->{currency}->{description};
my $feeamount = $line->{feeAmount};
my $amount = $line->{amount};
my $gebuehr = sprintf('%.8f', $feeamount );
$gesamtgebuehr += $gebuehr;
$gesamt += $amount;
#append_file('/mnt/h/Download/nicehashmining.csv', "Mining (kommerziell),$amount,$currencies,0,EUR,$gebuehr,$currencies,NiceHash,,,$datetime\n");
}
$min = localtime($min / 1000);
$max = localtime($max / 1000);
my $eur = $btcwerte{'BTC'};
my $btchenner = 0.00307542;
my $gesamteuro = sprintf('%.2f', ( $gesamt * $eur ) );
my $gebuehreuro = sprintf('%.2f', ( $gesamtgebuehr * $eur ) );
my $gesamtgebeuro = sprintf('%.2f', ( ($gesamt - $gesamtgebuehr) * $eur ) );
my $btchennereuro = sprintf('%.2f', ( $btchenner * $eur ) ); # Henner 150 Euro
my $btcsteffeneuro = sprintf('%.2f', ( ($curwerte{'BTC'} - $btchenner ) * $eur ) ); #
print 'von '.$min->ymd.' - '.$max->ymd."\n";
print "\n";
print "─── Mining ───────────────────────────────────────────────────────────────────────────────────\n";
print " BTC:\t$gesamt\t €: $gesamteuro\n";
print " Gebuehr:\t" . sprintf('%.8f', $gesamtgebuehr). "\t €: $gebuehreuro\n";
print "nach Gebuehr:\t". sprintf('%.8f',($gesamt - $gesamtgebuehr)). "\t €: $gesamtgebeuro\n";
print "─── Trading ────────────────────────────────────────────────────────────│\n";
print "BTC H:\t". sprintf('%.8f', $btchenner ). "\t €: $btchennereuro\t← 150\t→ ". _rotodergruen( _prozent(150,$btchennereuro)) ." %\t│───────────────│──────────────\n";
print "BTC S:\t". sprintf('%.8f', ($curwerte{'BTC'} - $btchenner - $gesamt) ). "\t €: $btcsteffeneuro". "\t← ".sprintf('%.2f', $washabich{'BTC'} - 150). "\t→ ". _rotodergruen(_prozent( $washabich{'BTC'} - 150,$btcsteffeneuro))." %\t│ ".sprintf('%.4f', $eur ). " €\t│ ".sprintf('%.2f',$avgineuro{'BTC'} ). " €\n";
my $maxsteffen = $btcsteffeneuro;
my $maxsteffenbtc = sprintf('%.8f', ($btcwerte{'BTC'} - $btchenner) );
for my $cu ( sort keys %btcwerte ) {
next if ( $cu eq 'BTC' );
$maxsteffen += sprintf('%.2f', ( $curwerte{$cu} * $btcwerte{$cu} ) );
$maxsteffenbtc += sprintf('%.8f', $curwerte{$cu} );
# print sprintf('%.8f', $btcwerte{$cu}). "\n";
my $pro = _prozent($curwerte{$cu} * $avgineuro{$cu}, $curwerte{$cu} * $btcwerte{$cu} );
print "$cu:\t".sprintf('%.8f', $curwerte{$cu} ). "\t €: ".sprintf('%.2f', ( $curwerte{$cu} * $btcwerte{$cu} ) ). "\t← ".sprintf('%.2f', $curwerte{$cu} * $avgineuro{$cu} ). "\t→ ". _rotodergruen($pro) . " %\t│ ".sprintf('%.4f',$btcwerte{$cu} )." €\t│ ".sprintf('%.4f',$avgineuro{$cu} ). " €\n";
}
print "─── result ─────────────────────────────────────────────────────────────│───────────────│──────────────\n";
my $totaleuro = $get_accounts2->{total}->{totalBalance} * $eur;
print "Umsatz NH:\t".sprintf('%.2f', $totaleuro)." €\n";
print "davon mining:\t$gesamtgebeuro €\n";
print "Rendite:\t". _rotodergruen( sprintf('%.2f', ($maxsteffen - $washabich{'EUR'}))) . " €\n";
print "ohne mining:\t". _rotodergruen(sprintf('%.2f', ($maxsteffen - $washabich{'EUR'} - $gesamtgebeuro))) . " €\n";
print "-=-=-=-=-=-=-=-=-=-=-=-=-=-\n";
print "Einsatz NH:\t$washabich{'EUR'} €\n";
my $su = 0;
for my $exch ( sort keys %washabichwoanders ) {
print "$exch:\t$washabichwoanders{$exch} €\n";
$su += $washabichwoanders{$exch};
}
$su += $washabich{'EUR'};
print "===========================\n";
print "Einsatz gesamt:\t$su €\n";
my @dateien = read_dir('./' );
for my $d ( @dateien ) {
copy( '/home/steffen/scripte/nicehash/'.$d, '/mnt/e/Programmierung/Perl/NiceHash' );
}
sub _prozent {
my ($ist, $soll) = @_;
if ( $ist ) {
my $result = sprintf('%.0f', ( ($soll * 100) / $ist - 100));
if ( $result !~ /-/ ) {
$result = " $result";
}
return $result;
} else {
return 0;
}
}
sub _rotodergruen {
my ($text) = @_;
if ( $text =~ /-/ ) {
return "\e[31m$text\e[0m";
} else {
return "\e[32m$text\e[0m";
}
}
1;
+336
View File
@@ -0,0 +1,336 @@
from datetime import datetime
from time import mktime
import uuid
import hmac
import requests
import json
from hashlib import sha256
import optparse
import sys
import dumper
class public_api:
def __init__(self, host, verbose=False):
self.host = host
self.verbose = verbose
def request(self, method, path, query, body):
url = self.host + path
if query:
url += '?' + query
if self.verbose:
print(method, url)
s = requests.Session()
if body:
body_json = json.dumps(body)
response = s.request(method, url, data=body_json)
else:
response = s.request(method, url)
if response.status_code == 200:
return response.json()
elif response.content:
raise Exception(str(response.status_code) + ": " + response.reason + ": " + str(response.content))
else:
raise Exception(str(response.status_code) + ": " + response.reason)
def get_current_global_stats(self):
return self.request('GET', '/main/api/v2/public/stats/global/current/', '', None)
def get_global_stats_24(self):
return self.request('GET', '/main/api/v2/public/stats/global/24h/', '', None)
def get_active_orders(self):
return self.request('GET', '/main/api/v2/public/orders/active/', '', None)
def get_active_orders2(self):
return self.request('GET', '/main/api/v2/public/orders/active2/', '', None)
def buy_info(self):
return self.request('GET', '/main/api/v2/public/buy/info/', '', None)
def get_algorithms(self):
return self.request('GET', '/main/api/v2/mining/algorithms/', '', None)
def get_markets(self):
return self.request('GET', '/main/api/v2/mining/markets/', '', None)
def get_currencies(self):
return self.request('GET', '/main/api/v2/public/currencies/', '', None)
def get_multialgo_info(self):
return self.request('GET', '/main/api/v2/public/simplemultialgo/info/', '', None)
def get_exchange_markets_info(self):
return self.request('GET', '/exchange/api/v2/info/status', '', None)
def get_exchange_trades(self, market):
return self.request('GET', '/exchange/api/v2/trades', 'market=' + market, None)
def get_candlesticks(self, market, from_s, to_s, resolution):
return self.request('GET', '/exchange/api/v2/candlesticks', "market={}&from={}&to={}&resolution={}".format(market, from_s, to_s, resolution), None)
def get_exchange_orderbook(self, market, limit):
return self.request('GET', '/exchange/api/v2/orderbook', "market={}&limit={}".format(market, limit), None)
class private_api:
def __init__(self, host, organisation_id, key, secret, verbose=False):
self.key = key
self.secret = secret
self.organisation_id = organisation_id
self.host = host
self.verbose = verbose
def request(self, method, path, query, body):
xtime = self.get_epoch_ms_from_now()
print(xtime)
xnonce = str(uuid.uuid4())
print(xnonce)
message = bytearray(self.key, 'utf-8')
message += bytearray('\x00', 'utf-8')
message += bytearray(str(xtime), 'utf-8')
message += bytearray('\x00', 'utf-8')
message += bytearray(xnonce, 'utf-8')
message += bytearray('\x00', 'utf-8')
message += bytearray('\x00', 'utf-8')
message += bytearray(self.organisation_id, 'utf-8')
message += bytearray('\x00', 'utf-8')
message += bytearray('\x00', 'utf-8')
message += bytearray(method, 'utf-8')
message += bytearray('\x00', 'utf-8')
message += bytearray(path, 'utf-8')
message += bytearray('\x00', 'utf-8')
message += bytearray(query, 'utf-8')
print(query)
if body:
body_json = json.dumps(body)
message += bytearray('\x00', 'utf-8')
message += bytearray(body_json, 'utf-8')
digest = hmac.new(bytearray(self.secret, 'utf-8'), message, sha256).hexdigest()
xauth = self.key + ":" + digest
headers = {
'X-Time': str(xtime),
'X-Nonce': xnonce,
'X-Auth': xauth,
'Content-Type': 'application/json',
'X-Organization-Id': self.organisation_id,
'X-Request-Id': str(uuid.uuid4())
}
print(headers)
s = requests.Session()
s.headers = headers
url = self.host + path
if query:
url += '?' + query
if self.verbose:
print(method, url)
if body:
response = s.request(method, url, data=body_json)
else:
response = s.request(method, url)
if response.status_code == 200:
return response.json()
elif response.content:
raise Exception(str(response.status_code) + ": " + response.reason + ": " + str(response.content))
else:
raise Exception(str(response.status_code) + ": " + response.reason)
def get_epoch_ms_from_now(self):
now = datetime.now()
now_ec_since_epoch = mktime(now.timetuple()) + now.microsecond / 1000000.0
return int(now_ec_since_epoch * 1000)
def algo_settings_from_response(self, algorithm, algo_response):
algo_setting = None
for item in algo_response['miningAlgorithms']:
if item['algorithm'] == algorithm:
algo_setting = item
if algo_setting is None:
raise Exception('Settings for algorithm not found in algo_response parameter')
return algo_setting
def get_accounts(self):
return self.request('GET', '/main/api/v2/accounting/accounts2/', '', None)
def get_accounts_for_currency(self, currency):
return self.request('GET', '/main/api/v2/accounting/account2/' + currency, '', None)
def get_withdrawal_addresses(self, currency, size, page):
params = "currency={}&size={}&page={}".format(currency, size, page)
return self.request('GET', '/main/api/v2/accounting/withdrawalAddresses/', params, None)
def get_withdrawal_types(self):
return self.request('GET', '/main/api/v2/accounting/withdrawalAddresses/types/', '', None)
def withdraw_request(self, address_id, amount, currency):
withdraw_data = {
"withdrawalAddressId": address_id,
"amount": amount,
"currency": currency
}
return self.request('POST', '/main/api/v2/accounting/withdrawal/', '', withdraw_data)
def get_my_active_orders(self, algorithm, market, limit):
ts = self.get_epoch_ms_from_now()
params = "algorithm={}&market={}&ts={}&limit={}&op=LT".format(algorithm, market, ts, limit)
return self.request('GET', '/main/api/v2/hashpower/myOrders', params, None)
def create_pool(self, name, algorithm, pool_host, pool_port, username, password):
pool_data = {
"name": name,
"algorithm": algorithm,
"stratumHostname": pool_host,
"stratumPort": pool_port,
"username": username,
"password": password
}
return self.request('POST', '/main/api/v2/pool/', '', pool_data)
def delete_pool(self, pool_id):
return self.request('DELETE', '/main/api/v2/pool/' + pool_id, '', None)
def get_my_pools(self, page, size):
return self.request('GET', '/main/api/v2/pools/', '', None)
def get_hashpower_orderbook(self, algorithm):
return self.request('GET', '/main/api/v2/hashpower/orderBook/', 'algorithm=' + algorithm, None )
def create_hashpower_order(self, market, type, algorithm, price, limit, amount, pool_id, algo_response):
algo_setting = self.algo_settings_from_response(algorithm, algo_response)
order_data = {
"market": market,
"algorithm": algorithm,
"amount": amount,
"price": price,
"limit": limit,
"poolId": pool_id,
"type": type,
"marketFactor": algo_setting['marketFactor'],
"displayMarketFactor": algo_setting['displayMarketFactor']
}
return self.request('POST', '/main/api/v2/hashpower/order/', '', order_data)
def cancel_hashpower_order(self, order_id):
return self.request('DELETE', '/main/api/v2/hashpower/order/' + order_id, '', None)
def refill_hashpower_order(self, order_id, amount):
refill_data = {
"amount": amount
}
return self.request('POST', '/main/api/v2/hashpower/order/' + order_id + '/refill/', '', refill_data)
def set_price_hashpower_order(self, order_id, price, algorithm, algo_response):
algo_setting = self.algo_settings_from_response(algorithm, algo_response)
price_data = {
"price": price,
"marketFactor": algo_setting['marketFactor'],
"displayMarketFactor": algo_setting['displayMarketFactor']
}
return self.request('POST', '/main/api/v2/hashpower/order/' + order_id + '/updatePriceAndLimit/', '',
price_data)
def set_limit_hashpower_order(self, order_id, limit, algorithm, algo_response):
algo_setting = self.algo_settings_from_response(algorithm, algo_response)
limit_data = {
"limit": limit,
"marketFactor": algo_setting['marketFactor'],
"displayMarketFactor": algo_setting['displayMarketFactor']
}
return self.request('POST', '/main/api/v2/hashpower/order/' + order_id + '/updatePriceAndLimit/', '',
limit_data)
def set_price_and_limit_hashpower_order(self, order_id, price, limit, algorithm, algo_response):
algo_setting = self.algo_settings_from_response(algorithm, algo_response)
price_data = {
"price": price,
"limit": limit,
"marketFactor": algo_setting['marketFactor'],
"displayMarketFactor": algo_setting['displayMarketFactor']
}
return self.request('POST', '/main/api/v2/hashpower/order/' + order_id + '/updatePriceAndLimit/', '',
price_data)
def get_my_exchange_orders(self, market):
return self.request('GET', '/exchange/api/v2/myOrders', 'market=' + market, None)
def get_my_exchange_trades(self, market):
return self.request('GET','/exchange/api/v2/myTrades', 'market=' + market, None)
def create_exchange_limit_order(self, market, side, quantity, price):
query = "market={}&side={}&type=limit&quantity={}&price={}".format(market, side, quantity, price)
return self.request('POST', '/exchange/api/v2/order', query, None)
def create_exchange_buy_market_order(self, market, quantity):
query = "market={}&side=buy&type=market&secQuantity={}".format(market, quantity)
return self.request('POST', '/exchange/api/v2/order', query, None)
def create_exchange_sell_market_order(self, market, quantity):
query = "market={}&side=sell&type=market&quantity={}".format(market, quantity)
return self.request('POST', '/exchange/api/v2/order', query, None)
def cancel_exchange_order(self, market, order_id):
query = "market={}&orderId={}".format(market, order_id)
return self.request('DELETE', '/exchange/api/v2/order', query, None)
def get_payouts(self):
return self.request('GET', '/main/api/v2/mining/rigs/payouts/', '', None)
if __name__ == "__main__":
parser = optparse.OptionParser()
parser.add_option('-b', '--base_url', dest="base", help="Api base url", default="https://api2.nicehash.com")
parser.add_option('-o', '--organization_id', dest="org", help="Organization id")
parser.add_option('-k', '--key', dest="key", help="Api key")
parser.add_option('-s', '--secret', dest="secret", help="Secret for api key")
parser.add_option('-m', '--method', dest="method", help="Method for request", default="GET")
parser.add_option('-p', '--path', dest="path", help="Path for request", default="/")
parser.add_option('-q', '--params', dest="params", help="Parameters for request")
parser.add_option('-d', '--body', dest="body", help="Body for request")
options, args = parser.parse_args()
private_api = private_api(options.base, options.org, options.key, options.secret)
params = ''
if options.params is not None:
params = options.params
try:
response = private_api.request(options.method, options.path, params, options.body)
except Exception as ex:
print("Unexpected error:", ex)
exit(1)
print(response)
exit(0)
Binary file not shown.
+12
View File
@@ -0,0 +1,12 @@
import nicehash
import json
host = 'https://api2.nicehash.com'
organisation_id = '4c615374-bf85-42fd-860d-b1bf4568c01f'
key = '8bcbda58-5a26-4ce4-8e61-3a0fd894cfbb'
secret = '59dc1ee5-a0e6-4ba6-9a9c-a043c350b88b84266786-2d14-4b9f-9ae5-d168ed8376b7'
private_api = nicehash.private_api(host, organisation_id, key, secret)
payouts = private_api.get_payouts()
# print(y)
+85
View File
@@ -0,0 +1,85 @@
Type,Buy Amount,Buy Currency,Sell Amount,Sell Currency,Fee,Fee Currency,Exchange,Trade-Group,Comment,Date
Mining (kommerziell),0.00001429,BTC,0,EUR,0.00000029,BTC,NiceHash,,,2021-03-20 05:05:26
Mining (kommerziell),0.00001569,BTC,0,EUR,0.00000031,BTC,NiceHash,,,2021-03-19 21:06:23
Mining (kommerziell),0.00001564,BTC,0,EUR,0.00000031,BTC,NiceHash,,,2021-03-19 13:07:00
Mining (kommerziell),0.00001619,BTC,0,EUR,0.00000032,BTC,NiceHash,,,2021-03-19 05:06:00
Mining (kommerziell),0.00001835,BTC,0,EUR,0.00000037,BTC,NiceHash,,,2021-03-18 21:05:55
Mining (kommerziell),0.00001552,BTC,0,EUR,0.00000031,BTC,NiceHash,,,2021-03-18 13:05:49
Mining (kommerziell),0.00001794,BTC,0,EUR,0.00000036,BTC,NiceHash,,,2021-03-18 05:05:21
Mining (kommerziell),0.00001897,BTC,0,EUR,0.00000038,BTC,NiceHash,,,2021-03-17 21:04:35
Mining (kommerziell),0.00001575,BTC,0,EUR,0.00000032,BTC,NiceHash,,,2021-03-17 13:06:30
Mining (kommerziell),0.00001061,BTC,0,EUR,0.00000021,BTC,NiceHash,,,2021-03-17 05:05:23
Mining (kommerziell),0.00001939,BTC,0,EUR,0.00000039,BTC,NiceHash,,,2021-03-16 21:06:46
Mining (kommerziell),0.00001648,BTC,0,EUR,0.00000033,BTC,NiceHash,,,2021-03-16 13:04:12
Mining (kommerziell),0.0000139,BTC,0,EUR,0.00000028,BTC,NiceHash,,,2021-03-16 05:04:50
Mining (kommerziell),0.00001859,BTC,0,EUR,0.00000037,BTC,NiceHash,,,2021-03-15 21:09:55
Mining (kommerziell),0.0000175,BTC,0,EUR,0.00000035,BTC,NiceHash,,,2021-03-15 13:08:04
Mining (kommerziell),0.00001672,BTC,0,EUR,0.00000033,BTC,NiceHash,,,2021-03-15 05:06:25
Mining (kommerziell),0.00001704,BTC,0,EUR,0.00000034,BTC,NiceHash,,,2021-03-14 21:03:56
Mining (kommerziell),0.00001595,BTC,0,EUR,0.00000032,BTC,NiceHash,,,2021-03-14 13:04:44
Mining (kommerziell),0.00001757,BTC,0,EUR,0.00000035,BTC,NiceHash,,,2021-03-14 05:03:25
Mining (kommerziell),0.00001619,BTC,0,EUR,0.00000032,BTC,NiceHash,,,2021-03-13 21:04:25
Mining (kommerziell),0.00001659,BTC,0,EUR,0.00000033,BTC,NiceHash,,,2021-03-13 13:07:03
Mining (kommerziell),0.00001618,BTC,0,EUR,0.00000032,BTC,NiceHash,,,2021-03-13 05:03:48
Mining (kommerziell),0.00001818,BTC,0,EUR,0.00000036,BTC,NiceHash,,,2021-03-12 21:03:50
Mining (kommerziell),0.00001654,BTC,0,EUR,0.00000033,BTC,NiceHash,,,2021-03-12 13:06:54
Mining (kommerziell),0.00001706,BTC,0,EUR,0.00000034,BTC,NiceHash,,,2021-03-12 05:04:33
Mining (kommerziell),0.00001634,BTC,0,EUR,0.00000033,BTC,NiceHash,,,2021-03-11 21:06:11
Mining (kommerziell),0.00001505,BTC,0,EUR,0.00000030,BTC,NiceHash,,,2021-03-11 13:06:38
Mining (kommerziell),0.00001524,BTC,0,EUR,0.00000030,BTC,NiceHash,,,2021-03-11 05:04:54
Mining (kommerziell),0.0000172,BTC,0,EUR,0.00000034,BTC,NiceHash,,,2021-03-10 21:10:50
Mining (kommerziell),0.00001674,BTC,0,EUR,0.00000033,BTC,NiceHash,,,2021-03-10 13:07:12
Mining (kommerziell),0.00001683,BTC,0,EUR,0.00000034,BTC,NiceHash,,,2021-03-10 05:02:42
Mining (kommerziell),0.00001738,BTC,0,EUR,0.00000035,BTC,NiceHash,,,2021-03-09 21:06:57
Mining (kommerziell),0.00001675,BTC,0,EUR,0.00000034,BTC,NiceHash,,,2021-03-09 13:07:56
Mining (kommerziell),0.00001666,BTC,0,EUR,0.00000033,BTC,NiceHash,,,2021-03-09 05:03:28
Mining (kommerziell),0.00001755,BTC,0,EUR,0.00000035,BTC,NiceHash,,,2021-03-08 21:08:11
Mining (kommerziell),0.00001614,BTC,0,EUR,0.00000032,BTC,NiceHash,,,2021-03-08 13:03:42
Mining (kommerziell),0.00001574,BTC,0,EUR,0.00000031,BTC,NiceHash,,,2021-03-08 05:03:50
Mining (kommerziell),0.00001754,BTC,0,EUR,0.00000035,BTC,NiceHash,,,2021-03-07 21:03:32
Mining (kommerziell),0.00001505,BTC,0,EUR,0.00000030,BTC,NiceHash,,,2021-03-07 13:02:02
Mining (kommerziell),0.00001249,BTC,0,EUR,0.00000025,BTC,NiceHash,,,2021-03-07 05:02:55
Mining (kommerziell),0.0000149,BTC,0,EUR,0.00000030,BTC,NiceHash,,,2021-03-06 21:02:07
Mining (kommerziell),0.00001398,BTC,0,EUR,0.00000028,BTC,NiceHash,,,2021-03-06 13:02:03
Mining (kommerziell),0.00001523,BTC,0,EUR,0.00000030,BTC,NiceHash,,,2021-03-06 05:03:14
Mining (kommerziell),0.00001548,BTC,0,EUR,0.00000031,BTC,NiceHash,,,2021-03-05 21:02:46
Mining (kommerziell),0.00001539,BTC,0,EUR,0.00000031,BTC,NiceHash,,,2021-03-05 13:00:12
Mining (kommerziell),0.00001183,BTC,0,EUR,0.00000024,BTC,NiceHash,,,2021-03-05 05:03:55
Mining (kommerziell),0.00001613,BTC,0,EUR,0.00000032,BTC,NiceHash,,,2021-03-04 21:05:13
Mining (kommerziell),0.00001532,BTC,0,EUR,0.00000031,BTC,NiceHash,,,2021-03-04 13:07:26
Mining (kommerziell),0.00001729,BTC,0,EUR,0.00000035,BTC,NiceHash,,,2021-03-04 05:05:52
Mining (kommerziell),0.00001778,BTC,0,EUR,0.00000036,BTC,NiceHash,,,2021-03-03 21:07:33
Mining (kommerziell),0.00001513,BTC,0,EUR,0.00000030,BTC,NiceHash,,,2021-03-03 13:06:29
Mining (kommerziell),0.00001422,BTC,0,EUR,0.00000028,BTC,NiceHash,,,2021-03-03 05:01:14
Mining (kommerziell),0.00001707,BTC,0,EUR,0.00000034,BTC,NiceHash,,,2021-03-02 21:08:06
Mining (kommerziell),0.00001513,BTC,0,EUR,0.00000030,BTC,NiceHash,,,2021-03-02 13:03:15
Mining (kommerziell),0.00001541,BTC,0,EUR,0.00000031,BTC,NiceHash,,,2021-03-02 05:06:50
Mining (kommerziell),0.00001662,BTC,0,EUR,0.00000033,BTC,NiceHash,,,2021-03-01 21:08:01
Mining (kommerziell),0.00001477,BTC,0,EUR,0.00000030,BTC,NiceHash,,,2021-03-01 13:07:28
Mining (kommerziell),0.0000125,BTC,0,EUR,0.00000025,BTC,NiceHash,,,2021-03-01 05:05:15
Mining (kommerziell),0.00001166,BTC,0,EUR,0.00000023,BTC,NiceHash,,,2021-02-28 21:03:50
Mining (kommerziell),0.0000139,BTC,0,EUR,0.00000028,BTC,NiceHash,,,2021-02-28 13:04:30
Mining (kommerziell),0.00001338,BTC,0,EUR,0.00000027,BTC,NiceHash,,,2021-02-28 09:40:45
Mining (kommerziell),0.0000125,BTC,0,EUR,0.00000025,BTC,NiceHash,,,2021-02-27 21:41:07
Mining (kommerziell),0.00001591,BTC,0,EUR,0.00000032,BTC,NiceHash,,,2021-02-27 09:05:05
Mining (kommerziell),0.00001789,BTC,0,EUR,0.00000036,BTC,NiceHash,,,2021-02-27 01:04:06
Mining (kommerziell),0.00001791,BTC,0,EUR,0.00000036,BTC,NiceHash,,,2021-02-26 17:03:53
Mining (kommerziell),0.00001767,BTC,0,EUR,0.00000035,BTC,NiceHash,,,2021-02-26 09:05:19
Mining (kommerziell),0.0000164,BTC,0,EUR,0.00000033,BTC,NiceHash,,,2021-02-26 01:04:34
Mining (kommerziell),0.00001252,BTC,0,EUR,0.00000025,BTC,NiceHash,,,2021-02-25 13:04:29
Mining (kommerziell),0.00001845,BTC,0,EUR,0.00000037,BTC,NiceHash,,,2021-02-25 01:25:43
Mining (kommerziell),0.00001115,BTC,0,EUR,0.00000022,BTC,NiceHash,,,2021-02-24 17:11:55
Mining (kommerziell),0.00001923,BTC,0,EUR,0.00000038,BTC,NiceHash,,,2021-02-24 05:04:40
Mining (kommerziell),0.00001008,BTC,0,EUR,0.00000020,BTC,NiceHash,,,2021-02-23 21:06:16
Mining (kommerziell),0.00001343,BTC,0,EUR,0.00000027,BTC,NiceHash,,,2021-02-23 17:07:07
Mining (kommerziell),0.00002585,BTC,0,EUR,0.00000052,BTC,NiceHash,,,2021-02-23 13:07:26
Mining (kommerziell),0.00001466,BTC,0,EUR,0.00000029,BTC,NiceHash,,,2021-02-23 05:06:07
Mining (kommerziell),0.0000206,BTC,0,EUR,0.00000041,BTC,NiceHash,,,2021-02-22 21:07:19
Mining (kommerziell),0.00001279,BTC,0,EUR,0.00000026,BTC,NiceHash,,,2021-02-22 07:00:22
Mining (kommerziell),0.00001782,BTC,0,EUR,0.00000036,BTC,NiceHash,,,2021-02-21 17:15:09
Mining (kommerziell),0.00001091,BTC,0,EUR,0.00000022,BTC,NiceHash,,,2021-02-21 07:00:36
Mining (kommerziell),0.00001108,BTC,0,EUR,0.00000022,BTC,NiceHash,,,2021-02-20 21:08:36
Mining (kommerziell),0.00001055,BTC,0,EUR,0.00000021,BTC,NiceHash,,,2021-02-20 17:09:42
Mining (kommerziell),0.00001456,BTC,0,EUR,0.00000029,BTC,NiceHash,,,2021-02-20 13:07:35
Mining (kommerziell),0.00001113,BTC,0,EUR,0.00000022,BTC,NiceHash,,,2021-02-19 21:11:54
Mining (kommerziell),0.00001173,BTC,0,EUR,0.00000023,BTC,NiceHash,,,2021-02-19 17:15:32
1 Type Buy Amount Buy Currency Sell Amount Sell Currency Fee Fee Currency Exchange Trade-Group Comment Date
2 Mining (kommerziell) 0.00001429 BTC 0 EUR 0.00000029 BTC NiceHash 2021-03-20 05:05:26
3 Mining (kommerziell) 0.00001569 BTC 0 EUR 0.00000031 BTC NiceHash 2021-03-19 21:06:23
4 Mining (kommerziell) 0.00001564 BTC 0 EUR 0.00000031 BTC NiceHash 2021-03-19 13:07:00
5 Mining (kommerziell) 0.00001619 BTC 0 EUR 0.00000032 BTC NiceHash 2021-03-19 05:06:00
6 Mining (kommerziell) 0.00001835 BTC 0 EUR 0.00000037 BTC NiceHash 2021-03-18 21:05:55
7 Mining (kommerziell) 0.00001552 BTC 0 EUR 0.00000031 BTC NiceHash 2021-03-18 13:05:49
8 Mining (kommerziell) 0.00001794 BTC 0 EUR 0.00000036 BTC NiceHash 2021-03-18 05:05:21
9 Mining (kommerziell) 0.00001897 BTC 0 EUR 0.00000038 BTC NiceHash 2021-03-17 21:04:35
10 Mining (kommerziell) 0.00001575 BTC 0 EUR 0.00000032 BTC NiceHash 2021-03-17 13:06:30
11 Mining (kommerziell) 0.00001061 BTC 0 EUR 0.00000021 BTC NiceHash 2021-03-17 05:05:23
12 Mining (kommerziell) 0.00001939 BTC 0 EUR 0.00000039 BTC NiceHash 2021-03-16 21:06:46
13 Mining (kommerziell) 0.00001648 BTC 0 EUR 0.00000033 BTC NiceHash 2021-03-16 13:04:12
14 Mining (kommerziell) 0.0000139 BTC 0 EUR 0.00000028 BTC NiceHash 2021-03-16 05:04:50
15 Mining (kommerziell) 0.00001859 BTC 0 EUR 0.00000037 BTC NiceHash 2021-03-15 21:09:55
16 Mining (kommerziell) 0.0000175 BTC 0 EUR 0.00000035 BTC NiceHash 2021-03-15 13:08:04
17 Mining (kommerziell) 0.00001672 BTC 0 EUR 0.00000033 BTC NiceHash 2021-03-15 05:06:25
18 Mining (kommerziell) 0.00001704 BTC 0 EUR 0.00000034 BTC NiceHash 2021-03-14 21:03:56
19 Mining (kommerziell) 0.00001595 BTC 0 EUR 0.00000032 BTC NiceHash 2021-03-14 13:04:44
20 Mining (kommerziell) 0.00001757 BTC 0 EUR 0.00000035 BTC NiceHash 2021-03-14 05:03:25
21 Mining (kommerziell) 0.00001619 BTC 0 EUR 0.00000032 BTC NiceHash 2021-03-13 21:04:25
22 Mining (kommerziell) 0.00001659 BTC 0 EUR 0.00000033 BTC NiceHash 2021-03-13 13:07:03
23 Mining (kommerziell) 0.00001618 BTC 0 EUR 0.00000032 BTC NiceHash 2021-03-13 05:03:48
24 Mining (kommerziell) 0.00001818 BTC 0 EUR 0.00000036 BTC NiceHash 2021-03-12 21:03:50
25 Mining (kommerziell) 0.00001654 BTC 0 EUR 0.00000033 BTC NiceHash 2021-03-12 13:06:54
26 Mining (kommerziell) 0.00001706 BTC 0 EUR 0.00000034 BTC NiceHash 2021-03-12 05:04:33
27 Mining (kommerziell) 0.00001634 BTC 0 EUR 0.00000033 BTC NiceHash 2021-03-11 21:06:11
28 Mining (kommerziell) 0.00001505 BTC 0 EUR 0.00000030 BTC NiceHash 2021-03-11 13:06:38
29 Mining (kommerziell) 0.00001524 BTC 0 EUR 0.00000030 BTC NiceHash 2021-03-11 05:04:54
30 Mining (kommerziell) 0.0000172 BTC 0 EUR 0.00000034 BTC NiceHash 2021-03-10 21:10:50
31 Mining (kommerziell) 0.00001674 BTC 0 EUR 0.00000033 BTC NiceHash 2021-03-10 13:07:12
32 Mining (kommerziell) 0.00001683 BTC 0 EUR 0.00000034 BTC NiceHash 2021-03-10 05:02:42
33 Mining (kommerziell) 0.00001738 BTC 0 EUR 0.00000035 BTC NiceHash 2021-03-09 21:06:57
34 Mining (kommerziell) 0.00001675 BTC 0 EUR 0.00000034 BTC NiceHash 2021-03-09 13:07:56
35 Mining (kommerziell) 0.00001666 BTC 0 EUR 0.00000033 BTC NiceHash 2021-03-09 05:03:28
36 Mining (kommerziell) 0.00001755 BTC 0 EUR 0.00000035 BTC NiceHash 2021-03-08 21:08:11
37 Mining (kommerziell) 0.00001614 BTC 0 EUR 0.00000032 BTC NiceHash 2021-03-08 13:03:42
38 Mining (kommerziell) 0.00001574 BTC 0 EUR 0.00000031 BTC NiceHash 2021-03-08 05:03:50
39 Mining (kommerziell) 0.00001754 BTC 0 EUR 0.00000035 BTC NiceHash 2021-03-07 21:03:32
40 Mining (kommerziell) 0.00001505 BTC 0 EUR 0.00000030 BTC NiceHash 2021-03-07 13:02:02
41 Mining (kommerziell) 0.00001249 BTC 0 EUR 0.00000025 BTC NiceHash 2021-03-07 05:02:55
42 Mining (kommerziell) 0.0000149 BTC 0 EUR 0.00000030 BTC NiceHash 2021-03-06 21:02:07
43 Mining (kommerziell) 0.00001398 BTC 0 EUR 0.00000028 BTC NiceHash 2021-03-06 13:02:03
44 Mining (kommerziell) 0.00001523 BTC 0 EUR 0.00000030 BTC NiceHash 2021-03-06 05:03:14
45 Mining (kommerziell) 0.00001548 BTC 0 EUR 0.00000031 BTC NiceHash 2021-03-05 21:02:46
46 Mining (kommerziell) 0.00001539 BTC 0 EUR 0.00000031 BTC NiceHash 2021-03-05 13:00:12
47 Mining (kommerziell) 0.00001183 BTC 0 EUR 0.00000024 BTC NiceHash 2021-03-05 05:03:55
48 Mining (kommerziell) 0.00001613 BTC 0 EUR 0.00000032 BTC NiceHash 2021-03-04 21:05:13
49 Mining (kommerziell) 0.00001532 BTC 0 EUR 0.00000031 BTC NiceHash 2021-03-04 13:07:26
50 Mining (kommerziell) 0.00001729 BTC 0 EUR 0.00000035 BTC NiceHash 2021-03-04 05:05:52
51 Mining (kommerziell) 0.00001778 BTC 0 EUR 0.00000036 BTC NiceHash 2021-03-03 21:07:33
52 Mining (kommerziell) 0.00001513 BTC 0 EUR 0.00000030 BTC NiceHash 2021-03-03 13:06:29
53 Mining (kommerziell) 0.00001422 BTC 0 EUR 0.00000028 BTC NiceHash 2021-03-03 05:01:14
54 Mining (kommerziell) 0.00001707 BTC 0 EUR 0.00000034 BTC NiceHash 2021-03-02 21:08:06
55 Mining (kommerziell) 0.00001513 BTC 0 EUR 0.00000030 BTC NiceHash 2021-03-02 13:03:15
56 Mining (kommerziell) 0.00001541 BTC 0 EUR 0.00000031 BTC NiceHash 2021-03-02 05:06:50
57 Mining (kommerziell) 0.00001662 BTC 0 EUR 0.00000033 BTC NiceHash 2021-03-01 21:08:01
58 Mining (kommerziell) 0.00001477 BTC 0 EUR 0.00000030 BTC NiceHash 2021-03-01 13:07:28
59 Mining (kommerziell) 0.0000125 BTC 0 EUR 0.00000025 BTC NiceHash 2021-03-01 05:05:15
60 Mining (kommerziell) 0.00001166 BTC 0 EUR 0.00000023 BTC NiceHash 2021-02-28 21:03:50
61 Mining (kommerziell) 0.0000139 BTC 0 EUR 0.00000028 BTC NiceHash 2021-02-28 13:04:30
62 Mining (kommerziell) 0.00001338 BTC 0 EUR 0.00000027 BTC NiceHash 2021-02-28 09:40:45
63 Mining (kommerziell) 0.0000125 BTC 0 EUR 0.00000025 BTC NiceHash 2021-02-27 21:41:07
64 Mining (kommerziell) 0.00001591 BTC 0 EUR 0.00000032 BTC NiceHash 2021-02-27 09:05:05
65 Mining (kommerziell) 0.00001789 BTC 0 EUR 0.00000036 BTC NiceHash 2021-02-27 01:04:06
66 Mining (kommerziell) 0.00001791 BTC 0 EUR 0.00000036 BTC NiceHash 2021-02-26 17:03:53
67 Mining (kommerziell) 0.00001767 BTC 0 EUR 0.00000035 BTC NiceHash 2021-02-26 09:05:19
68 Mining (kommerziell) 0.0000164 BTC 0 EUR 0.00000033 BTC NiceHash 2021-02-26 01:04:34
69 Mining (kommerziell) 0.00001252 BTC 0 EUR 0.00000025 BTC NiceHash 2021-02-25 13:04:29
70 Mining (kommerziell) 0.00001845 BTC 0 EUR 0.00000037 BTC NiceHash 2021-02-25 01:25:43
71 Mining (kommerziell) 0.00001115 BTC 0 EUR 0.00000022 BTC NiceHash 2021-02-24 17:11:55
72 Mining (kommerziell) 0.00001923 BTC 0 EUR 0.00000038 BTC NiceHash 2021-02-24 05:04:40
73 Mining (kommerziell) 0.00001008 BTC 0 EUR 0.00000020 BTC NiceHash 2021-02-23 21:06:16
74 Mining (kommerziell) 0.00001343 BTC 0 EUR 0.00000027 BTC NiceHash 2021-02-23 17:07:07
75 Mining (kommerziell) 0.00002585 BTC 0 EUR 0.00000052 BTC NiceHash 2021-02-23 13:07:26
76 Mining (kommerziell) 0.00001466 BTC 0 EUR 0.00000029 BTC NiceHash 2021-02-23 05:06:07
77 Mining (kommerziell) 0.0000206 BTC 0 EUR 0.00000041 BTC NiceHash 2021-02-22 21:07:19
78 Mining (kommerziell) 0.00001279 BTC 0 EUR 0.00000026 BTC NiceHash 2021-02-22 07:00:22
79 Mining (kommerziell) 0.00001782 BTC 0 EUR 0.00000036 BTC NiceHash 2021-02-21 17:15:09
80 Mining (kommerziell) 0.00001091 BTC 0 EUR 0.00000022 BTC NiceHash 2021-02-21 07:00:36
81 Mining (kommerziell) 0.00001108 BTC 0 EUR 0.00000022 BTC NiceHash 2021-02-20 21:08:36
82 Mining (kommerziell) 0.00001055 BTC 0 EUR 0.00000021 BTC NiceHash 2021-02-20 17:09:42
83 Mining (kommerziell) 0.00001456 BTC 0 EUR 0.00000029 BTC NiceHash 2021-02-20 13:07:35
84 Mining (kommerziell) 0.00001113 BTC 0 EUR 0.00000022 BTC NiceHash 2021-02-19 21:11:54
85 Mining (kommerziell) 0.00001173 BTC 0 EUR 0.00000023 BTC NiceHash 2021-02-19 17:15:32
+14
View File
@@ -0,0 +1,14 @@
use lib '/home/steffen/scripte/Nicehash';
use Nicehashapi;
use Data::Printer;
my $api = Nicehashapi->new(
key => '8bcbda58-5a26-4ce4-8e61-3a0fd894cfbb',
secret => '59dc1ee5-a0e6-4ba6-9a9c-a043c350b88b84266786-2d14-4b9f-9ae5-d168ed8376b7',
organisation_id => '4c615374-bf85-42fd-860d-b1bf4568c01f'
);
my $data = $api->get_payouts;
p $data->{list};
+1
View File
@@ -0,0 +1 @@
{"prices":[[1589500800000,9065.58786685775],[1589587200000,8602.515037129955],[1589673600000,8663.505801366833],[1589760000000,8932.517630843413],[1589846400000,8893.367790448134],[1589932800000,8932.534067290839],[1590019200000,8676.19057826932],[1590105600000,8274.210078575754],[1590192000000,8377.38284872019],[1590278400000,8412.788365688826],[1590364800000,8004.922136091924],[1590451200000,8149.898829672694],[1590537600000,8050.512264626668],[1590624000000,8327.485032318018],[1590710400000,8618.036354672655],[1590796800000,8489.07476063891],[1590883200000,8701.218324700274],[1590969600000,8513.951139778357],[1591056000000,9139.332656460681],[1591142400000,8506.999104148701],[1591228800000,8584.870098314315],[1591315200000,8614.252385199457],[1591401600000,8535.123073514798],[1591488000000,8557.640255583976],[1591574400000,8604.7475065964],[1591660800000,8646.746499888024],[1591747200000,8617.878073129736],[1591833600000,8685.052389860908],[1591920000000,8258.589886025959],[1592006400000,8413.32049257224],[1592092800000,8413.267325810108],[1592179200000,8304.428332243695],[1592265600000,8321.983173811092],[1592352000000,8455.98220240086],[1592438400000,8418.558997364693],[1592524800000,8386.735504604761],[1592611200000,8330.22592679265],[1592697600000,8374.295608719134],[1592784000000,8319.838528907994],[1592870400000,8584.508072201117],[1592956800000,8507.06595186394],[1593043200000,8255.814453055787],[1593129600000,8252.296333941973],[1593216000000,8171.198437888594],[1593302400000,8034.824156146585],[1593388800000,8141.368843362288],[1593475200000,8163.959724661558],[1593561600000,8144.167549314312],[1593648000000,8203.363708558636],[1593734400000,8091.533089939427],[1593820800000,8065.3684415381895],[1593907200000,8121.749286492225],[1593993600000,8078.705100885547],[1594080000000,8259.12793830662],[1594166400000,8205.990402445177],[1594252800000,8319.298777202946],[1594339200000,8181.099093247821],[1594425600000,8214.533825232174],[1594512000000,8171.962177274989],[1594598400000,8219.669309084125],[1594684800000,8141.989652316821],[1594771200000,8105.9734060818755],[1594857600000,8060.5611939591245],[1594944000000,8022.554186634305],[1595030400000,8012.181511502039],[1595116800000,8021.70143789932],[1595203200000,8041.75186442637],[1595289600000,7998.4762466819175],[1595376000000,8132.522261758876],[1595462400000,8225.782663152648],[1595548800000,8268.647711869198],[1595635200000,8181.110755394266],[1595721600000,8314.849390480349],[1595808000000,8516.612323079422],[1595894400000,9317.952595801691],[1595980800000,9305.841377244684],[1596067200000,9411.765156730098],[1596153600000,9367.800977294917],[1596240000000,9615.200712279546],[1596326400000,10028.267261267707],[1596412800000,9394.032439349676],[1596499200000,9549.539792495829],[1596585600000,9472.358867901452],[1596672000000,9870.186405878985],[1596758400000,9908.763558966106],[1596844800000,9818.708410297182],[1596931200000,9960.957876348775],[1597017600000,9915.750087336437],[1597104000000,10104.850599220059],[1597190400000,9709.672976448235],[1597276800000,9816.775156630929],[1597363200000,10001.279526780683],[1597449600000,9945.064780536964],[1597536000000,10018.999358929797],[1597622400000,10041.99299246381],[1597708800000,10333.845746774328],[1597795200000,10003.13883962256],[1597881600000,9907.416497090384],[1597968000000,9993.443112482619],[1598054400000,9762.303593100985],[1598140800000,9899.437960198073],[1598227200000,9870.454289679794],[1598313600000,9971.48624607278],[1598400000000,9588.81006382656],[1598486400000,9683.68511565841],[1598572800000,9559.187782321487],[1598659200000,9674.642594493249],[1598745600000,9643.032509322002],[1598832000000,9818.956018885257],[1598918400000,9776.78535959722],[1599004800000,9974.610365860795],[1599091200000,9634.43790751692],[1599177600000,8613.253846922327],[1599264000000,8856.62006575121],[1599350400000,8597.555553056365],[1599436800000,8668.042597062857],[1599523200000,8765.924275376934],[1599609600000,8603.660583815532],[1599696000000,8666.32210124299],[1599782400000,8745.454087116239],[1599868800000,8761.244003123085],[1599955200000,8811.467026471148],[1600041600000,8723.336795824247],[1600128000000,8983.519437063293],[1600214400000,9109.291629624606],[1600300800000,9276.457153583979],[1600387200000,9228.814141975428],[1600473600000,9228.743337564398],[1600560000000,9361.72235984177],[1600646400000,9218.381071831582],[1600732800000,8872.842469854337],[1600819200000,8990.707407345302],[1600905600000,8769.23611779217],[1600992000000,9188.034600001185],[1601078400000,9184.111260761954],[1601164800000,9236.288187287017],[1601251200000,9252.775798367516],[1601337600000,9142.097204182532],[1601424000000,9229.987751235554],[1601510400000,9186.376992440666],[1601596800000,9049.721618464619],[1601683200000,9023.323353491749],[1601769600000,9001.117607747685],[1601856000000,9106.37607239346],[1601942400000,9148.35490107342],[1602028800000,9037.156332689581],[1602115200000,9066.58253791113],[16022Line truncated
+22
View File
@@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
+37
View File
@@ -0,0 +1,37 @@
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: "0 0 * * 6"
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!
# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
pip install -r requirements.txt
pytest
+39
View File
@@ -0,0 +1,39 @@
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# =========================
# Operating System Files
# =========================
# OSX
# =========================
.DS_Store
.AppleDouble
.LSOverride
# Icon must ends with two \r.
Icon␍
# Thumbnails
._*
# Files that might appear on external disk
.Spotlight-V100
.Trashes
*.wav
*.pyc
Binary file not shown.

After

Width:  |  Height:  |  Size: 270 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

+26
View File
@@ -0,0 +1,26 @@
import cv2
import sys
def blur_display(infile, nogui=False):
# The first argument is the image
image = cv2.imread(infile)
#conver to grayscale
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
#blur it
blurred_image = cv2.GaussianBlur(image, (7,7), 0)
if nogui:
cv2.imwrite('test_blurred.png', blurred_image)
else:
# Show all 3 images
cv2.imshow("Original Image", image)
cv2.imshow("Gray Image", gray_image)
cv2.imshow("Blurred Image", blurred_image)
cv2.waitKey(0)
if __name__ == "__main__":
blur_display(sys.argv[1])
Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

+96
View File
@@ -0,0 +1,96 @@
#!/usr/bin/python
import cv2
# The location in the picture which only has the shirt.
# Format is: x, y, x_size, y_size
# I found the x , y positions by opening the file in Gimp.
shirt_location = (240,378,120,120)
def find_rgb(blobs):
'''
Find the RGB values in blobs of data. The function loops over the blobs
and finds the average of the rgb values
Input: The output of the findBlobs() function
Output: The average rgb values are returned.
'''
red, green, blue = 0,0,0
for blob in blobs:
colors = cv2.mean(blob)
red += colors[0]
green += colors[1]
blue += colors[2]
red = red / len(blobs)
green = green / len(blobs)
blue = blue / len(blobs)
return red, green, blue
# Read the red and blue shirts
red = cv2.imread("red_train.jpg")
red2 = red[378:498, 240:360]
cv2.imshow("red ", red)
input("Press Enter to continue")
cv2.waitKey(0)
cv2.imshow("red cropped", red2)
input("Press Enter to continue")
cv2.waitKey(0)
blue = cv2.imread("blue_train.jpg")
blue2=blue[378:498, 240:360]
# See the color
print(cv2.mean(red2)) #(41.038071895424835, 1.3220588235294117, 194.17328431372547)
print(cv2.mean(blue2)) #(171.3142973856209, 61.778431372549015, 24.947303921568626)
# Clearly not red enough! Let's read the ideal colors
red_ideal = cv2.imread("red_ideal.jpg")
red_ideal = red_ideal[378:498, 240:360]
# Pure red!
cv2.mean(red_ideal) #(0.058333333333333334, 0.0, 254.0)
blue_ideal = cv2.imread("blue_ideal.jpg")
blue_ideal = blue_ideal[378:498, 240:360]
# Pure blue!
cv2.mean(blue_ideal) #(254.0, 0.0, 0.008333333333333333)
#blob params
params = cv2.SimpleBlobDetector_Params()
# Change thresholds
params.minThreshold = 0;
params.maxThreshold = 256;
# Set up the detector with default parameters.
detector = cv2.SimpleBlobDetector_create(params)
# Find the different colored blobs
blob_red= detector.detect(red2)
blob_blue=detector.detect(blue2)
print('blob_red ', blob_red, blob_blue)
# Find rgb values
red, green, blue = find_rgb(blob_red)
print("The RGB values for the red shirt are: red {} green {} blue {}".format(red, green, blue))
# The RGB values for the red shirt are: red 200.841750984 green 1.5193715676 blue 43.4040374198
red, green, blue = find_rgb(blob_blue)
print("The RGB values for the blue shirt are: red {} green {} blue {}".format(red, green, blue))
# The RGB values for the blue shirt are: red 29.0385591969 green 64.2966580905 blue 173.929505814
+34
View File
@@ -0,0 +1,34 @@
import cv2
import sys
def count_cards(infile="cards.jpg", nogui=False):
# Read the image
image = cv2.imread(infile)
#convert to grayscale
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
#blur it
blurred_image = cv2.GaussianBlur(gray_image, (7,7), 0)
# Run the Canny edge detector
canny = cv2.Canny(blurred_image, 30, 100)
contours, hierarchy= cv2.findContours(canny, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
image2 = image
cv2.drawContours(image2, contours, -1, (0,255,0), 2)
print("Number of objects found = ", len(contours))
if nogui:
cv2.imwrite('test_count_cards.png', image2)
return len(contours)
else:
# Show both our images
cv2.imshow("Original image", image)
cv2.imshow("Blurred image", blurred_image)
cv2.imshow("Canny", canny)
cv2.imshow("objects Found", image2)
cv2.waitKey(0)
if __name__ == "__main__":
count_cards()
+16
View File
@@ -0,0 +1,16 @@
import cv2
import sys
def display(infile, nogui=False):
image = cv2.imread(infile)
if nogui:
cv2.imwrite('test_display2.png', image)
else:
cv2.imshow("Image", image)
cv2.waitKey(0)
if __name__ == "__main__":
# Read the image. The first command line argument is the image
display(sys.argv[1])
+27
View File
@@ -0,0 +1,27 @@
import cv2
import sys
def edge_detect(infile, nogui=False):
# The first argument is the image
image = cv2.imread(infile)
#conver to grayscale
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
#blur it
blurred_image = cv2.GaussianBlur(gray_image, (7,7), 0)
# Use low thresholds
canny = cv2.Canny(blurred_image, 10, 30)
# Use high thresholds
canny2 = cv2.Canny(blurred_image, 50, 150)
if nogui:
cv2.imwrite('test_edge.png', canny2)
else:
cv2.imshow("Orignal Image", image)
cv2.imshow("Canny with low thresholds", canny)
cv2.imshow("Canny with high thresholds", canny2)
cv2.waitKey(0)
if __name__ == "__main__":
edge_detect(sys.argv[1])
+34
View File
@@ -0,0 +1,34 @@
#!/usr/bin/python
import sys
import cv2
def face_detect(imgpath, nogui = False, cascasdepath = "haarcascade_frontalface_default.xml"):
image = cv2.imread(imgpath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
face_cascade = cv2.CascadeClassifier(cascasdepath)
faces = face_cascade.detectMultiScale(
gray,
scaleFactor = 1.2,
minNeighbors = 5,
minSize = (30,30)
)
print("The number of faces found = ", len(faces))
for (x,y,w,h) in faces:
cv2.rectangle(image, (x,y), (x+h, y+h), (0, 255, 0), 2)
if nogui:
cv2.imwrite('test_face.png', image)
return len(faces)
else:
cv2.imshow("Faces found", image)
cv2.waitKey(0)
if __name__ == "__main__":
face_detect(sys.argv[1])
File diff suppressed because it is too large. Load diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

Binary file not shown.
+50
View File
@@ -0,0 +1,50 @@
#!/usr/bin/python
import sys
import cv2
import numpy as np
import time
if len(sys.argv) < 2:
video_capture = cv2.VideoCapture(0)
else:
filepath = sys.argv[1]
video_capture = cv2.VideoCapture(filepath)
# Read two frames, last and current, and convert current to gray.
ret, last_frame = video_capture.read()
ret, current_frame = video_capture.read()
gray = cv2.cvtColor(current_frame, cv2.COLOR_BGR2GRAY)
i = 0
while True:
last_frame = current_frame
ret, current_frame = video_capture.read()
if not ret:
break
gray = cv2.cvtColor(current_frame, cv2.COLOR_BGR2GRAY)
diff = cv2.absdiff(last_frame, current_frame)
'''
i += 1
if i == 10:
i = 0
print("Current frame = ", np.mean(current_frame))
print("Diff = ", np.mean(diff))
'''
if np.mean(diff) > 10:
print("Achtung! Motion detected")
cv2.imshow("Motion detected", diff)
time.sleep(0.1)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video_capture.release()
cv2.destroyAllWindows()
Binary file not shown.

After

Width:  |  Height:  |  Size: 264 KiB

@@ -0,0 +1,64 @@
#!/usr/bin/python
import sys
import cv2
import face_recognition
shan_image = face_recognition.load_image_file("shan.jpg")
shan_face_encoding = face_recognition.face_encodings(shan_image)[0]
ojas_image = face_recognition.load_image_file("ojas.jpg")
ojas_face_encoding = face_recognition.face_encodings(ojas_image)[0]
video_capture = cv2.VideoCapture(0)
counter = 0
face_names = []
while True:
ret, image = video_capture.read()
if not ret:
break
# Reduce face size to make calculations easier
small_frame = cv2.resize(image, (0, 0), fx=0.25, fy=0.25)
# to save cpu, only do calculations once every 10 frames
if counter % 3 == 0:
face_locations = face_recognition.face_locations(small_frame)
face_encodings = face_recognition.face_encodings(small_frame, face_locations)
for face_encoding in face_encodings:
# See if the face is a match for the known face(s)
match = face_recognition.compare_faces([shan_face_encoding, ojas_face_encoding], face_encoding)
name = "Unknown"
if match[0]:
name = "shantnu"
elif match[1]:
name = "ojas"
face_names.append(name)
for (top, right, bottom, left), name in zip(face_locations, face_names):
# Because we made the image smaller, now need to multiply by 4 to get correct size
top *= 4
right *= 4
bottom *= 4
left *= 4
cv2.rectangle(image, (left, top), (right, bottom), (0, 0, 255), 2)
# Draw a label with a name below the face
cv2.rectangle(image, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
cv2.putText(image, name, (left + 6, bottom - 6), cv2.FONT_HERSHEY_SIMPLEX, 1.0, (255, 255, 255), 1)
cv2.imshow('Video', image)
counter += 1
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video_capture.release()
cv2.destroyAllWindows()
Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.
@@ -0,0 +1,65 @@
#!/usr/bin/python
import sys
import cv2 as cv
def inside(r, q):
rx, ry, rw, rh = r
qx, qy, qw, qh = q
return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh
def draw_detections(img, rects, thickness = 1):
for x, y, w, h in rects:
# the HOG detector returns slightly larger rectangles than the real objects.
# so we slightly shrink the rectangles to get a nicer output.
pad_w, pad_h = int(0.15*w), int(0.05*h)
cv.rectangle(img, (x+pad_w, y+pad_h), (x+w-pad_w, y+h-pad_h), (0, 255, 0), thickness)
def webcam_face_detect(video_mode, nogui = False, cascasdepath = "haarcascade_frontalface_default.xml"):
hog = cv.HOGDescriptor()
hog.setSVMDetector( cv.HOGDescriptor_getDefaultPeopleDetector() )
video_capture = cv.VideoCapture(video_mode)
num_faces = 0
while True:
ret, image = video_capture.read()
if not ret:
break
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(
gray,
scaleFactor = 1.2,
minNeighbors = 5,
minSize = (30,30)
)
print("The number of faces found = ", len(faces))
num_faces = len(faces)
if not nogui:
for (x,y,w,h) in faces:
cv.rectangle(image, (x,y), (x+h, y+h), (0, 255, 0), 2)
cv.imshow("Faces found", image)
if cv.waitKey(1) & 0xFF == ord('q'):
break
video_capture.release()
cv.destroyAllWindows()
return num_faces
if __name__ == "__main__":
if len(sys.argv) < 2:
video_mode= 0
else:
video_mode = sys.argv[1]
webcam_face_detect(video_mode)
@@ -0,0 +1,52 @@
#!/usr/bin/python
import sys
import cv2
def webcam_face_detect(video_mode, nogui = False, cascasdepath = "haarcascade_frontalface_default.xml"):
face_cascade = cv2.CascadeClassifier(cascasdepath)
video_capture = cv2.VideoCapture(video_mode)
num_faces = 0
while True:
ret, image = video_capture.read()
if not ret:
break
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(
gray,
scaleFactor = 1.2,
minNeighbors = 5,
minSize = (30,30)
)
print("The number of faces found = ", len(faces))
num_faces = len(faces)
if not nogui:
for (x,y,w,h) in faces:
cv2.rectangle(image, (x,y), (x+h, y+h), (0, 255, 0), 2)
cv2.imshow("Faces found", image)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video_capture.release()
cv2.destroyAllWindows()
return num_faces
if __name__ == "__main__":
if len(sys.argv) < 2:
video_mode= 0
else:
video_mode = sys.argv[1]
webcam_face_detect(video_mode)
+17
View File
@@ -0,0 +1,17 @@
The MIT License (MIT)
Copyright (c) 2014 shantnu
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+9
View File
@@ -0,0 +1,9 @@
#!/usr/bin/python
import random
def gen_random_data():
arr = []
for i in range(1000000):
arr.append(random.random())
print("job done")
+8
View File
@@ -0,0 +1,8 @@
#!/usr/bin/python
import multiprocessing
from gen_rand import gen_random_data
if __name__ == '__main__':
for x in range(4):
process = multiprocessing.Process(target=gen_random_data)
process.start()
+8
View File
@@ -0,0 +1,8 @@
#!/usr/bin/python
from gen_rand import gen_random_data
if __name__ == '__main__':
gen_random_data()
gen_random_data()
gen_random_data()
gen_random_data()
+8
View File
@@ -0,0 +1,8 @@
#!/usr/bin/python
import threading
from gen_rand import gen_random_data
if __name__ == '__main__':
for x in range(4):
process = threading.Thread(target=gen_random_data)
process.start()
+145
View File
@@ -0,0 +1,145 @@
SUMMARY & USAGE LICENSE
=============================================
MovieLens data sets were collected by the GroupLens Research Project
at the University of Minnesota.
This data set consists of:
* 100,000 ratings (1-5) from 943 users on 1682 movies.
* Each user has rated at least 20 movies.
* Simple demographic info for the users (age, gender, occupation, zip)
The data was collected through the MovieLens web site
(movielens.umn.edu) during the seven-month period from September 19th,
1997 through April 22nd, 1998. This data has been cleaned up - users
who had less than 20 ratings or did not have complete demographic
information were removed from this data set. Detailed descriptions of
the data file can be found at the end of this file.
Neither the University of Minnesota nor any of the researchers
involved can guarantee the correctness of the data, its suitability
for any particular purpose, or the validity of results based on the
use of the data set. The data set may be used for any research
purposes under the following conditions:
* The user may not state or imply any endorsement from the
University of Minnesota or the GroupLens Research Group.
* The user must acknowledge the use of the data set in
publications resulting from the use of the data set, and must
send us an electronic or paper copy of those publications.
* The user may not redistribute the data without separate
permission.
* The user may not use this information for any commercial or
revenue-bearing purposes without first obtaining permission
from a faculty member of the GroupLens Research Project at the
University of Minnesota.
If you have any further questions or comments, please contact Jon Herlocker
<herlocke@cs.umn.edu>.
ACKNOWLEDGEMENTS
==============================================
Thanks to Al Borchers for cleaning up this data and writing the
accompanying scripts.
PUBLISHED WORK THAT HAS USED THIS DATASET
==============================================
Herlocker, J., Konstan, J., Borchers, A., Riedl, J.. An Algorithmic
Framework for Performing Collaborative Filtering. Proceedings of the
1999 Conference on Research and Development in Information
Retrieval. Aug. 1999.
FURTHER INFORMATION ABOUT THE GROUPLENS RESEARCH PROJECT
==============================================
The GroupLens Research Project is a research group in the Department
of Computer Science and Engineering at the University of Minnesota.
Members of the GroupLens Research Project are involved in many
research projects related to the fields of information filtering,
collaborative filtering, and recommender systems. The project is lead
by professors John Riedl and Joseph Konstan. The project began to
explore automated collaborative filtering in 1992, but is most well
known for its world wide trial of an automated collaborative filtering
system for Usenet news in 1996. The technology developed in the
Usenet trial formed the base for the formation of Net Perceptions,
Inc., which was founded by members of GroupLens Research. Since then
the project has expanded its scope to research overall information
filtering solutions, integrating in content-based methods as well as
improving current collaborative filtering technology.
Further information on the GroupLens Research project, including
research publications, can be found at the following web site:
http://www.grouplens.org/
GroupLens Research currently operates a movie recommender based on
collaborative filtering:
http://www.movielens.org/
DETAILED DESCRIPTIONS OF DATA FILES
==============================================
Here are brief descriptions of the data.
ml-data.tar.gz -- Compressed tar file. To rebuild the u data files do this:
gunzip ml-data.tar.gz
tar xvf ml-data.tar
mku.sh
u.data -- The full u data set, 100000 ratings by 943 users on 1682 items.
Each user has rated at least 20 movies. Users and items are
numbered consecutively from 1. The data is randomly
ordered. This is a tab separated list of
user id | item id | rating | timestamp.
The time stamps are unix seconds since 1/1/1970 UTC
u.info -- The number of users, items, and ratings in the u data set.
u.item -- Information about the items (movies); this is a tab separated
list of
movie id | movie title | release date | video release date |
IMDb URL | unknown | Action | Adventure | Animation |
Children's | Comedy | Crime | Documentary | Drama | Fantasy |
Film-Noir | Horror | Musical | Mystery | Romance | Sci-Fi |
Thriller | War | Western |
The last 19 fields are the genres, a 1 indicates the movie
is of that genre, a 0 indicates it is not; movies can be in
several genres at once.
The movie ids are the ones used in the u.data data set.
u.genre -- A list of the genres.
u.user -- Demographic information about the users; this is a tab
separated list of
user id | age | gender | occupation | zip code
The user ids are the ones used in the u.data data set.
u.occupation -- A list of the occupations.
u1.base -- The data sets u1.base and u1.test through u5.base and u5.test
u1.test are 80%/20% splits of the u data into training and test data.
u2.base Each of u1, ..., u5 have disjoint test sets; this if for
u2.test 5 fold cross validation (where you repeat your experiment
u3.base with each training and test set and average the results).
u3.test These data sets can be generated from u.data by mku.sh.
u4.base
u4.test
u5.base
u5.test
ua.base -- The data sets ua.base, ua.test, ub.base, and ub.test
ua.test split the u data into a training set and a test set with
ub.base exactly 10 ratings per user in the test set. The sets
ub.test ua.test and ub.test are disjoint. These data sets can
be generated from u.data by mku.sh.
allbut.pl -- The script that generates training and test sets where
all but n of a users ratings are in the training data.
mku.sh -- A shell script to generate all the u data sets from u.data.
+34
View File
@@ -0,0 +1,34 @@
#!/usr/local/bin/perl
# get args
if (@ARGV < 3) {
print STDERR "Usage: $0 base_name start stop max_test [ratings ...]\n";
exit 1;
}
$basename = shift;
$start = shift;
$stop = shift;
$maxtest = shift;
# open files
open( TESTFILE, ">$basename.test" ) or die "Cannot open $basename.test for writing\n";
open( BASEFILE, ">$basename.base" ) or die "Cannot open $basename.base for writing\n";
# init variables
$testcnt = 0;
while (<>) {
($user) = split;
if (! defined $ratingcnt{$user}) {
$ratingcnt{$user} = 0;
}
++$ratingcnt{$user};
if (($testcnt < $maxtest || $maxtest <= 0)
&& $ratingcnt{$user} >= $start && $ratingcnt{$user} <= $stop) {
++$testcnt;
print TESTFILE;
}
else {
print BASEFILE;
}
}
+25
View File
@@ -0,0 +1,25 @@
#!/bin/sh
trap `rm -f tmp.$$; exit 1` 1 2 15
for i in 1 2 3 4 5
do
head -`expr $i \* 20000` u.data | tail -20000 > tmp.$$
sort -t" " -k 1,1n -k 2,2n tmp.$$ > u$i.test
head -`expr \( $i - 1 \) \* 20000` u.data > tmp.$$
tail -`expr \( 5 - $i \) \* 20000` u.data >> tmp.$$
sort -t" " -k 1,1n -k 2,2n tmp.$$ > u$i.base
done
allbut.pl ua 1 10 100000 u.data
sort -t" " -k 1,1n -k 2,2n ua.base > tmp.$$
mv tmp.$$ ua.base
sort -t" " -k 1,1n -k 2,2n ua.test > tmp.$$
mv tmp.$$ ua.test
allbut.pl ub 11 20 100000 u.data
sort -t" " -k 1,1n -k 2,2n ub.base > tmp.$$
mv tmp.$$ ub.base
sort -t" " -k 1,1n -k 2,2n ub.test > tmp.$$
mv tmp.$$ ub.test
File diff suppressed because it is too large. Load diff
+20
View File
@@ -0,0 +1,20 @@
unknown|0
Action|1
Adventure|2
Animation|3
Children's|4
Comedy|5
Crime|6
Documentary|7
Drama|8
Fantasy|9
Film-Noir|10
Horror|11
Musical|12
Mystery|13
Romance|14
Sci-Fi|15
Thriller|16
War|17
Western|18
+3
View File
@@ -0,0 +1,3 @@
943 users
1682 items
100000 ratings
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,21 @@
administrator
artist
doctor
educator
engineer
entertainment
executive
healthcare
homemaker
lawyer
librarian
marketing
none
other
programmer
retired
salesman
scientist
student
technician
writer
+943
View File
@@ -0,0 +1,943 @@
1|24|M|technician|85711
2|53|F|other|94043
3|23|M|writer|32067
4|24|M|technician|43537
5|33|F|other|15213
6|42|M|executive|98101
7|57|M|administrator|91344
8|36|M|administrator|05201
9|29|M|student|01002
10|53|M|lawyer|90703
11|39|F|other|30329
12|28|F|other|06405
13|47|M|educator|29206
14|45|M|scientist|55106
15|49|F|educator|97301
16|21|M|entertainment|10309
17|30|M|programmer|06355
18|35|F|other|37212
19|40|M|librarian|02138
20|42|F|homemaker|95660
21|26|M|writer|30068
22|25|M|writer|40206
23|30|F|artist|48197
24|21|F|artist|94533
25|39|M|engineer|55107
26|49|M|engineer|21044
27|40|F|librarian|30030
28|32|M|writer|55369
29|41|M|programmer|94043
30|7|M|student|55436
31|24|M|artist|10003
32|28|F|student|78741
33|23|M|student|27510
34|38|F|administrator|42141
35|20|F|homemaker|42459
36|19|F|student|93117
37|23|M|student|55105
38|28|F|other|54467
39|41|M|entertainment|01040
40|38|M|scientist|27514
41|33|M|engineer|80525
42|30|M|administrator|17870
43|29|F|librarian|20854
44|26|M|technician|46260
45|29|M|programmer|50233
46|27|F|marketing|46538
47|53|M|marketing|07102
48|45|M|administrator|12550
49|23|F|student|76111
50|21|M|writer|52245
51|28|M|educator|16509
52|18|F|student|55105
53|26|M|programmer|55414
54|22|M|executive|66315
55|37|M|programmer|01331
56|25|M|librarian|46260
57|16|M|none|84010
58|27|M|programmer|52246
59|49|M|educator|08403
60|50|M|healthcare|06472
61|36|M|engineer|30040
62|27|F|administrator|97214
63|31|M|marketing|75240
64|32|M|educator|43202
65|51|F|educator|48118
66|23|M|student|80521
67|17|M|student|60402
68|19|M|student|22904
69|24|M|engineer|55337
70|27|M|engineer|60067
71|39|M|scientist|98034
72|48|F|administrator|73034
73|24|M|student|41850
74|39|M|scientist|T8H1N
75|24|M|entertainment|08816
76|20|M|student|02215
77|30|M|technician|29379
78|26|M|administrator|61801
79|39|F|administrator|03755
80|34|F|administrator|52241
81|21|M|student|21218
82|50|M|programmer|22902
83|40|M|other|44133
84|32|M|executive|55369
85|51|M|educator|20003
86|26|M|administrator|46005
87|47|M|administrator|89503
88|49|F|librarian|11701
89|43|F|administrator|68106
90|60|M|educator|78155
91|55|M|marketing|01913
92|32|M|entertainment|80525
93|48|M|executive|23112
94|26|M|student|71457
95|31|M|administrator|10707
96|25|F|artist|75206
97|43|M|artist|98006
98|49|F|executive|90291
99|20|M|student|63129
100|36|M|executive|90254
101|15|M|student|05146
102|38|M|programmer|30220
103|26|M|student|55108
104|27|M|student|55108
105|24|M|engineer|94043
106|61|M|retired|55125
107|39|M|scientist|60466
108|44|M|educator|63130
109|29|M|other|55423
110|19|M|student|77840
111|57|M|engineer|90630
112|30|M|salesman|60613
113|47|M|executive|95032
114|27|M|programmer|75013
115|31|M|engineer|17110
116|40|M|healthcare|97232
117|20|M|student|16125
118|21|M|administrator|90210
119|32|M|programmer|67401
120|47|F|other|06260
121|54|M|librarian|99603
122|32|F|writer|22206
123|48|F|artist|20008
124|34|M|student|60615
125|30|M|lawyer|22202
126|28|F|lawyer|20015
127|33|M|none|73439
128|24|F|marketing|20009
129|36|F|marketing|07039
130|20|M|none|60115
131|59|F|administrator|15237
132|24|M|other|94612
133|53|M|engineer|78602
134|31|M|programmer|80236
135|23|M|student|38401
136|51|M|other|97365
137|50|M|educator|84408
138|46|M|doctor|53211
139|20|M|student|08904
140|30|F|student|32250
141|49|M|programmer|36117
142|13|M|other|48118
143|42|M|technician|08832
144|53|M|programmer|20910
145|31|M|entertainment|V3N4P
146|45|M|artist|83814
147|40|F|librarian|02143
148|33|M|engineer|97006
149|35|F|marketing|17325
150|20|F|artist|02139
151|38|F|administrator|48103
152|33|F|educator|68767
153|25|M|student|60641
154|25|M|student|53703
155|32|F|other|11217
156|25|M|educator|08360
157|57|M|engineer|70808
158|50|M|educator|27606
159|23|F|student|55346
160|27|M|programmer|66215
161|50|M|lawyer|55104
162|25|M|artist|15610
163|49|M|administrator|97212
164|47|M|healthcare|80123
165|20|F|other|53715
166|47|M|educator|55113
167|37|M|other|L9G2B
168|48|M|other|80127
169|52|F|other|53705
170|53|F|healthcare|30067
171|48|F|educator|78750
172|55|M|marketing|22207
173|56|M|other|22306
174|30|F|administrator|52302
175|26|F|scientist|21911
176|28|M|scientist|07030
177|20|M|programmer|19104
178|26|M|other|49512
179|15|M|entertainment|20755
180|22|F|administrator|60202
181|26|M|executive|21218
182|36|M|programmer|33884
183|33|M|scientist|27708
184|37|M|librarian|76013
185|53|F|librarian|97403
186|39|F|executive|00000
187|26|M|educator|16801
188|42|M|student|29440
189|32|M|artist|95014
190|30|M|administrator|95938
191|33|M|administrator|95161
192|42|M|educator|90840
193|29|M|student|49931
194|38|M|administrator|02154
195|42|M|scientist|93555
196|49|M|writer|55105
197|55|M|technician|75094
198|21|F|student|55414
199|30|M|writer|17604
200|40|M|programmer|93402
201|27|M|writer|E2A4H
202|41|F|educator|60201
203|25|F|student|32301
204|52|F|librarian|10960
205|47|M|lawyer|06371
206|14|F|student|53115
207|39|M|marketing|92037
208|43|M|engineer|01720
209|33|F|educator|85710
210|39|M|engineer|03060
211|66|M|salesman|32605
212|49|F|educator|61401
213|33|M|executive|55345
214|26|F|librarian|11231
215|35|M|programmer|63033
216|22|M|engineer|02215
217|22|M|other|11727
218|37|M|administrator|06513
219|32|M|programmer|43212
220|30|M|librarian|78205
221|19|M|student|20685
222|29|M|programmer|27502
223|19|F|student|47906
224|31|F|educator|43512
225|51|F|administrator|58202
226|28|M|student|92103
227|46|M|executive|60659
228|21|F|student|22003
229|29|F|librarian|22903
230|28|F|student|14476
231|48|M|librarian|01080
232|45|M|scientist|99709
233|38|M|engineer|98682
234|60|M|retired|94702
235|37|M|educator|22973
236|44|F|writer|53214
237|49|M|administrator|63146
238|42|F|administrator|44124
239|39|M|artist|95628
240|23|F|educator|20784
241|26|F|student|20001
242|33|M|educator|31404
243|33|M|educator|60201
244|28|M|technician|80525
245|22|M|student|55109
246|19|M|student|28734
247|28|M|engineer|20770
248|25|M|student|37235
249|25|M|student|84103
250|29|M|executive|95110
251|28|M|doctor|85032
252|42|M|engineer|07733
253|26|F|librarian|22903
254|44|M|educator|42647
255|23|M|entertainment|07029
256|35|F|none|39042
257|17|M|student|77005
258|19|F|student|77801
259|21|M|student|48823
260|40|F|artist|89801
261|28|M|administrator|85202
262|19|F|student|78264
263|41|M|programmer|55346
264|36|F|writer|90064
265|26|M|executive|84601
266|62|F|administrator|78756
267|23|M|engineer|83716
268|24|M|engineer|19422
269|31|F|librarian|43201
270|18|F|student|63119
271|51|M|engineer|22932
272|33|M|scientist|53706
273|50|F|other|10016
274|20|F|student|55414
275|38|M|engineer|92064
276|21|M|student|95064
277|35|F|administrator|55406
278|37|F|librarian|30033
279|33|M|programmer|85251
280|30|F|librarian|22903
281|15|F|student|06059
282|22|M|administrator|20057
283|28|M|programmer|55305
284|40|M|executive|92629
285|25|M|programmer|53713
286|27|M|student|15217
287|21|M|salesman|31211
288|34|M|marketing|23226
289|11|M|none|94619
290|40|M|engineer|93550
291|19|M|student|44106
292|35|F|programmer|94703
293|24|M|writer|60804
294|34|M|technician|92110
295|31|M|educator|50325
296|43|F|administrator|16803
297|29|F|educator|98103
298|44|M|executive|01581
299|29|M|doctor|63108
300|26|F|programmer|55106
301|24|M|student|55439
302|42|M|educator|77904
303|19|M|student|14853
304|22|F|student|71701
305|23|M|programmer|94086
306|45|M|other|73132
307|25|M|student|55454
308|60|M|retired|95076
309|40|M|scientist|70802
310|37|M|educator|91711
311|32|M|technician|73071
312|48|M|other|02110
313|41|M|marketing|60035
314|20|F|student|08043
315|31|M|educator|18301
316|43|F|other|77009
317|22|M|administrator|13210
318|65|M|retired|06518
319|38|M|programmer|22030
320|19|M|student|24060
321|49|F|educator|55413
322|20|M|student|50613
323|21|M|student|19149
324|21|F|student|02176
325|48|M|technician|02139
326|41|M|administrator|15235
327|22|M|student|11101
328|51|M|administrator|06779
329|48|M|educator|01720
330|35|F|educator|33884
331|33|M|entertainment|91344
332|20|M|student|40504
333|47|M|other|V0R2M
334|32|M|librarian|30002
335|45|M|executive|33775
336|23|M|salesman|42101
337|37|M|scientist|10522
338|39|F|librarian|59717
339|35|M|lawyer|37901
340|46|M|engineer|80123
341|17|F|student|44405
342|25|F|other|98006
343|43|M|engineer|30093
344|30|F|librarian|94117
345|28|F|librarian|94143
346|34|M|other|76059
347|18|M|student|90210
348|24|F|student|45660
349|68|M|retired|61455
350|32|M|student|97301
351|61|M|educator|49938
352|37|F|programmer|55105
353|25|M|scientist|28480
354|29|F|librarian|48197
355|25|M|student|60135
356|32|F|homemaker|92688
357|26|M|executive|98133
358|40|M|educator|10022
359|22|M|student|61801
360|51|M|other|98027
361|22|M|student|44074
362|35|F|homemaker|85233
363|20|M|student|87501
364|63|M|engineer|01810
365|29|M|lawyer|20009
366|20|F|student|50670
367|17|M|student|37411
368|18|M|student|92113
369|24|M|student|91335
370|52|M|writer|08534
371|36|M|engineer|99206
372|25|F|student|66046
373|24|F|other|55116
374|36|M|executive|78746
375|17|M|entertainment|37777
376|28|F|other|10010
377|22|M|student|18015
378|35|M|student|02859
379|44|M|programmer|98117
380|32|M|engineer|55117
381|33|M|artist|94608
382|45|M|engineer|01824
383|42|M|administrator|75204
384|52|M|programmer|45218
385|36|M|writer|10003
386|36|M|salesman|43221
387|33|M|entertainment|37412
388|31|M|other|36106
389|44|F|writer|83702
390|42|F|writer|85016
391|23|M|student|84604
392|52|M|writer|59801
393|19|M|student|83686
394|25|M|administrator|96819
395|43|M|other|44092
396|57|M|engineer|94551
397|17|M|student|27514
398|40|M|other|60008
399|25|M|other|92374
400|33|F|administrator|78213
401|46|F|healthcare|84107
402|30|M|engineer|95129
403|37|M|other|06811
404|29|F|programmer|55108
405|22|F|healthcare|10019
406|52|M|educator|93109
407|29|M|engineer|03261
408|23|M|student|61755
409|48|M|administrator|98225
410|30|F|artist|94025
411|34|M|educator|44691
412|25|M|educator|15222
413|55|M|educator|78212
414|24|M|programmer|38115
415|39|M|educator|85711
416|20|F|student|92626
417|27|F|other|48103
418|55|F|none|21206
419|37|M|lawyer|43215
420|53|M|educator|02140
421|38|F|programmer|55105
422|26|M|entertainment|94533
423|64|M|other|91606
424|36|F|marketing|55422
425|19|M|student|58644
426|55|M|educator|01602
427|51|M|doctor|85258
428|28|M|student|55414
429|27|M|student|29205
430|38|M|scientist|98199
431|24|M|marketing|92629
432|22|M|entertainment|50311
433|27|M|artist|11211
434|16|F|student|49705
435|24|M|engineer|60007
436|30|F|administrator|17345
437|27|F|other|20009
438|51|F|administrator|43204
439|23|F|administrator|20817
440|30|M|other|48076
441|50|M|technician|55013
442|22|M|student|85282
443|35|M|salesman|33308
444|51|F|lawyer|53202
445|21|M|writer|92653
446|57|M|educator|60201
447|30|M|administrator|55113
448|23|M|entertainment|10021
449|23|M|librarian|55021
450|35|F|educator|11758
451|16|M|student|48446
452|35|M|administrator|28018
453|18|M|student|06333
454|57|M|other|97330
455|48|M|administrator|83709
456|24|M|technician|31820
457|33|F|salesman|30011
458|47|M|technician|Y1A6B
459|22|M|student|29201
460|44|F|other|60630
461|15|M|student|98102
462|19|F|student|02918
463|48|F|healthcare|75218
464|60|M|writer|94583
465|32|M|other|05001
466|22|M|student|90804
467|29|M|engineer|91201
468|28|M|engineer|02341
469|60|M|educator|78628
470|24|M|programmer|10021
471|10|M|student|77459
472|24|M|student|87544
473|29|M|student|94708
474|51|M|executive|93711
475|30|M|programmer|75230
476|28|M|student|60440
477|23|F|student|02125
478|29|M|other|10019
479|30|M|educator|55409
480|57|M|retired|98257
481|73|M|retired|37771
482|18|F|student|40256
483|29|M|scientist|43212
484|27|M|student|21208
485|44|F|educator|95821
486|39|M|educator|93101
487|22|M|engineer|92121
488|48|M|technician|21012
489|55|M|other|45218
490|29|F|artist|V5A2B
491|43|F|writer|53711
492|57|M|educator|94618
493|22|M|engineer|60090
494|38|F|administrator|49428
495|29|M|engineer|03052
496|21|F|student|55414
497|20|M|student|50112
498|26|M|writer|55408
499|42|M|programmer|75006
500|28|M|administrator|94305
501|22|M|student|10025
502|22|M|student|23092
503|50|F|writer|27514
504|40|F|writer|92115
505|27|F|other|20657
506|46|M|programmer|03869
507|18|F|writer|28450
508|27|M|marketing|19382
509|23|M|administrator|10011
510|34|M|other|98038
511|22|M|student|21250
512|29|M|other|20090
513|43|M|administrator|26241
514|27|M|programmer|20707
515|53|M|marketing|49508
516|53|F|librarian|10021
517|24|M|student|55454
518|49|F|writer|99709
519|22|M|other|55320
520|62|M|healthcare|12603
521|19|M|student|02146
522|36|M|engineer|55443
523|50|F|administrator|04102
524|56|M|educator|02159
525|27|F|administrator|19711
526|30|M|marketing|97124
527|33|M|librarian|12180
528|18|M|student|55104
529|47|F|administrator|44224
530|29|M|engineer|94040
531|30|F|salesman|97408
532|20|M|student|92705
533|43|M|librarian|02324
534|20|M|student|05464
535|45|F|educator|80302
536|38|M|engineer|30078
537|36|M|engineer|22902
538|31|M|scientist|21010
539|53|F|administrator|80303
540|28|M|engineer|91201
541|19|F|student|84302
542|21|M|student|60515
543|33|M|scientist|95123
544|44|F|other|29464
545|27|M|technician|08052
546|36|M|executive|22911
547|50|M|educator|14534
548|51|M|writer|95468
549|42|M|scientist|45680
550|16|F|student|95453
551|25|M|programmer|55414
552|45|M|other|68147
553|58|M|educator|62901
554|32|M|scientist|62901
555|29|F|educator|23227
556|35|F|educator|30606
557|30|F|writer|11217
558|56|F|writer|63132
559|69|M|executive|10022
560|32|M|student|10003
561|23|M|engineer|60005
562|54|F|administrator|20879
563|39|F|librarian|32707
564|65|M|retired|94591
565|40|M|student|55422
566|20|M|student|14627
567|24|M|entertainment|10003
568|39|M|educator|01915
569|34|M|educator|91903
570|26|M|educator|14627
571|34|M|artist|01945
572|51|M|educator|20003
573|68|M|retired|48911
574|56|M|educator|53188
575|33|M|marketing|46032
576|48|M|executive|98281
577|36|F|student|77845
578|31|M|administrator|M7A1A
579|32|M|educator|48103
580|16|M|student|17961
581|37|M|other|94131
582|17|M|student|93003
583|44|M|engineer|29631
584|25|M|student|27511
585|69|M|librarian|98501
586|20|M|student|79508
587|26|M|other|14216
588|18|F|student|93063
589|21|M|lawyer|90034
590|50|M|educator|82435
591|57|F|librarian|92093
592|18|M|student|97520
593|31|F|educator|68767
594|46|M|educator|M4J2K
595|25|M|programmer|31909
596|20|M|artist|77073
597|23|M|other|84116
598|40|F|marketing|43085
599|22|F|student|R3T5K
600|34|M|programmer|02320
601|19|F|artist|99687
602|47|F|other|34656
603|21|M|programmer|47905
604|39|M|educator|11787
605|33|M|engineer|33716
606|28|M|programmer|63044
607|49|F|healthcare|02154
608|22|M|other|10003
609|13|F|student|55106
610|22|M|student|21227
611|46|M|librarian|77008
612|36|M|educator|79070
613|37|F|marketing|29678
614|54|M|educator|80227
615|38|M|educator|27705
616|55|M|scientist|50613
617|27|F|writer|11201
618|15|F|student|44212
619|17|M|student|44134
620|18|F|writer|81648
621|17|M|student|60402
622|25|M|programmer|14850
623|50|F|educator|60187
624|19|M|student|30067
625|27|M|programmer|20723
626|23|M|scientist|19807
627|24|M|engineer|08034
628|13|M|none|94306
629|46|F|other|44224
630|26|F|healthcare|55408
631|18|F|student|38866
632|18|M|student|55454
633|35|M|programmer|55414
634|39|M|engineer|T8H1N
635|22|M|other|23237
636|47|M|educator|48043
637|30|M|other|74101
638|45|M|engineer|01940
639|42|F|librarian|12065
640|20|M|student|61801
641|24|M|student|60626
642|18|F|student|95521
643|39|M|scientist|55122
644|51|M|retired|63645
645|27|M|programmer|53211
646|17|F|student|51250
647|40|M|educator|45810
648|43|M|engineer|91351
649|20|M|student|39762
650|42|M|engineer|83814
651|65|M|retired|02903
652|35|M|other|22911
653|31|M|executive|55105
654|27|F|student|78739
655|50|F|healthcare|60657
656|48|M|educator|10314
657|26|F|none|78704
658|33|M|programmer|92626
659|31|M|educator|54248
660|26|M|student|77380
661|28|M|programmer|98121
662|55|M|librarian|19102
663|26|M|other|19341
664|30|M|engineer|94115
665|25|M|administrator|55412
666|44|M|administrator|61820
667|35|M|librarian|01970
668|29|F|writer|10016
669|37|M|other|20009
670|30|M|technician|21114
671|21|M|programmer|91919
672|54|F|administrator|90095
673|51|M|educator|22906
674|13|F|student|55337
675|34|M|other|28814
676|30|M|programmer|32712
677|20|M|other|99835
678|50|M|educator|61462
679|20|F|student|54302
680|33|M|lawyer|90405
681|44|F|marketing|97208
682|23|M|programmer|55128
683|42|M|librarian|23509
684|28|M|student|55414
685|32|F|librarian|55409
686|32|M|educator|26506
687|31|F|healthcare|27713
688|37|F|administrator|60476
689|25|M|other|45439
690|35|M|salesman|63304
691|34|M|educator|60089
692|34|M|engineer|18053
693|43|F|healthcare|85210
694|60|M|programmer|06365
695|26|M|writer|38115
696|55|M|other|94920
697|25|M|other|77042
698|28|F|programmer|06906
699|44|M|other|96754
700|17|M|student|76309
701|51|F|librarian|56321
702|37|M|other|89104
703|26|M|educator|49512
704|51|F|librarian|91105
705|21|F|student|54494
706|23|M|student|55454
707|56|F|librarian|19146
708|26|F|homemaker|96349
709|21|M|other|N4T1A
710|19|M|student|92020
711|22|F|student|15203
712|22|F|student|54901
713|42|F|other|07204
714|26|M|engineer|55343
715|21|M|technician|91206
716|36|F|administrator|44265
717|24|M|technician|84105
718|42|M|technician|64118
719|37|F|other|V0R2H
720|49|F|administrator|16506
721|24|F|entertainment|11238
722|50|F|homemaker|17331
723|26|M|executive|94403
724|31|M|executive|40243
725|21|M|student|91711
726|25|F|administrator|80538
727|25|M|student|78741
728|58|M|executive|94306
729|19|M|student|56567
730|31|F|scientist|32114
731|41|F|educator|70403
732|28|F|other|98405
733|44|F|other|60630
734|25|F|other|63108
735|29|F|healthcare|85719
736|48|F|writer|94618
737|30|M|programmer|98072
738|35|M|technician|95403
739|35|M|technician|73162
740|25|F|educator|22206
741|25|M|writer|63108
742|35|M|student|29210
743|31|M|programmer|92660
744|35|M|marketing|47024
745|42|M|writer|55113
746|25|M|engineer|19047
747|19|M|other|93612
748|28|M|administrator|94720
749|33|M|other|80919
750|28|M|administrator|32303
751|24|F|other|90034
752|60|M|retired|21201
753|56|M|salesman|91206
754|59|F|librarian|62901
755|44|F|educator|97007
756|30|F|none|90247
757|26|M|student|55104
758|27|M|student|53706
759|20|F|student|68503
760|35|F|other|14211
761|17|M|student|97302
762|32|M|administrator|95050
763|27|M|scientist|02113
764|27|F|educator|62903
765|31|M|student|33066
766|42|M|other|10960
767|70|M|engineer|00000
768|29|M|administrator|12866
769|39|M|executive|06927
770|28|M|student|14216
771|26|M|student|15232
772|50|M|writer|27105
773|20|M|student|55414
774|30|M|student|80027
775|46|M|executive|90036
776|30|M|librarian|51157
777|63|M|programmer|01810
778|34|M|student|01960
779|31|M|student|K7L5J
780|49|M|programmer|94560
781|20|M|student|48825
782|21|F|artist|33205
783|30|M|marketing|77081
784|47|M|administrator|91040
785|32|M|engineer|23322
786|36|F|engineer|01754
787|18|F|student|98620
788|51|M|administrator|05779
789|29|M|other|55420
790|27|M|technician|80913
791|31|M|educator|20064
792|40|M|programmer|12205
793|22|M|student|85281
794|32|M|educator|57197
795|30|M|programmer|08610
796|32|F|writer|33755
797|44|F|other|62522
798|40|F|writer|64131
799|49|F|administrator|19716
800|25|M|programmer|55337
801|22|M|writer|92154
802|35|M|administrator|34105
803|70|M|administrator|78212
804|39|M|educator|61820
805|27|F|other|20009
806|27|M|marketing|11217
807|41|F|healthcare|93555
808|45|M|salesman|90016
809|50|F|marketing|30803
810|55|F|other|80526
811|40|F|educator|73013
812|22|M|technician|76234
813|14|F|student|02136
814|30|M|other|12345
815|32|M|other|28806
816|34|M|other|20755
817|19|M|student|60152
818|28|M|librarian|27514
819|59|M|administrator|40205
820|22|M|student|37725
821|37|M|engineer|77845
822|29|F|librarian|53144
823|27|M|artist|50322
824|31|M|other|15017
825|44|M|engineer|05452
826|28|M|artist|77048
827|23|F|engineer|80228
828|28|M|librarian|85282
829|48|M|writer|80209
830|46|M|programmer|53066
831|21|M|other|33765
832|24|M|technician|77042
833|34|M|writer|90019
834|26|M|other|64153
835|44|F|executive|11577
836|44|M|artist|10018
837|36|F|artist|55409
838|23|M|student|01375
839|38|F|entertainment|90814
840|39|M|artist|55406
841|45|M|doctor|47401
842|40|M|writer|93055
843|35|M|librarian|44212
844|22|M|engineer|95662
845|64|M|doctor|97405
846|27|M|lawyer|47130
847|29|M|student|55417
848|46|M|engineer|02146
849|15|F|student|25652
850|34|M|technician|78390
851|18|M|other|29646
852|46|M|administrator|94086
853|49|M|writer|40515
854|29|F|student|55408
855|53|M|librarian|04988
856|43|F|marketing|97215
857|35|F|administrator|V1G4L
858|63|M|educator|09645
859|18|F|other|06492
860|70|F|retired|48322
861|38|F|student|14085
862|25|M|executive|13820
863|17|M|student|60089
864|27|M|programmer|63021
865|25|M|artist|11231
866|45|M|other|60302
867|24|M|scientist|92507
868|21|M|programmer|55303
869|30|M|student|10025
870|22|M|student|65203
871|31|M|executive|44648
872|19|F|student|74078
873|48|F|administrator|33763
874|36|M|scientist|37076
875|24|F|student|35802
876|41|M|other|20902
877|30|M|other|77504
878|50|F|educator|98027
879|33|F|administrator|55337
880|13|M|student|83702
881|39|M|marketing|43017
882|35|M|engineer|40503
883|49|M|librarian|50266
884|44|M|engineer|55337
885|30|F|other|95316
886|20|M|student|61820
887|14|F|student|27249
888|41|M|scientist|17036
889|24|M|technician|78704
890|32|M|student|97301
891|51|F|administrator|03062
892|36|M|other|45243
893|25|M|student|95823
894|47|M|educator|74075
895|31|F|librarian|32301
896|28|M|writer|91505
897|30|M|other|33484
898|23|M|homemaker|61755
899|32|M|other|55116
900|60|M|retired|18505
901|38|M|executive|L1V3W
902|45|F|artist|97203
903|28|M|educator|20850
904|17|F|student|61073
905|27|M|other|30350
906|45|M|librarian|70124
907|25|F|other|80526
908|44|F|librarian|68504
909|50|F|educator|53171
910|28|M|healthcare|29301
911|37|F|writer|53210
912|51|M|other|06512
913|27|M|student|76201
914|44|F|other|08105
915|50|M|entertainment|60614
916|27|M|engineer|N2L5N
917|22|F|student|20006
918|40|M|scientist|70116
919|25|M|other|14216
920|30|F|artist|90008
921|20|F|student|98801
922|29|F|administrator|21114
923|21|M|student|E2E3R
924|29|M|other|11753
925|18|F|salesman|49036
926|49|M|entertainment|01701
927|23|M|programmer|55428
928|21|M|student|55408
929|44|M|scientist|53711
930|28|F|scientist|07310
931|60|M|educator|33556
932|58|M|educator|06437
933|28|M|student|48105
934|61|M|engineer|22902
935|42|M|doctor|66221
936|24|M|other|32789
937|48|M|educator|98072
938|38|F|technician|55038
939|26|F|student|33319
940|32|M|administrator|02215
941|20|M|student|97229
942|48|F|librarian|78209
943|22|M|student|77841
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+63
View File
@@ -0,0 +1,63 @@
import pandas as pd
import matplotlib.pyplot as plt
def obesity(excelfile="Obes-phys-acti-diet-eng-2014-tab.xls", nogui = False):
data = pd.ExcelFile(excelfile)
print(data.sheet_names)
# Read section 7.1 from the Excel file
# Define the columns to be read
columns1 = ['year', 'total', 'males', 'females']
data_gender = data.parse('7.1', skiprows=4, skipfooter=14, names=columns1)
#print data_gender
# Remove the N/A from the data
data_gender.dropna(inplace = True)
#print data_gender
data_gender.set_index('year', inplace=True)
# Plot all
data_gender.plot()
if not nogui:
plt.show()
# Read 2nd section, by age
data_age = data.parse('7.2', skiprows=4, skipfooter=14)
print(data_age)
# Rename unames to year
data_age.rename(columns={'Unnamed: 0': 'Year'}, inplace=True)
# Drop empties and reset index
data_age.dropna(inplace=True)
data_age.set_index('Year', inplace=True)
#plot
data_age.plot()
if not nogui:
plt.show()
# Plotting everything cause total to override everything. So drop it.
# Drop the total column and plot
data_age_minus_total = data_age.drop('Total', axis = 1)
data_age_minus_total.plot()
if not nogui:
plt.show()
plt.close()
#Plot children vs adults
data_age['Under 16'].plot(label = "Under 16")
data_age['25-34'].plot(label = "25-34")
plt.legend(loc="upper right")
if not nogui:
plt.show()
return data_age['Total'][1]
if __name__ == "__main__":
obesity()
+73
View File
@@ -0,0 +1,73 @@
import pandas as pd
import matplotlib.pyplot as plt
def movie(nogui=False, movielenspath=''):
user_columns = ['user_id', 'age', 'gender']
users = pd.read_csv(movielenspath + 'movie_lens/u.user', sep='|', names=user_columns, usecols=range(3))
rating_columns = ['user_id', 'movie_id', 'rating']
ratings = pd.read_csv(movielenspath + 'movie_lens/u.data', sep='\t', names=rating_columns, usecols=range(3))
movie_columns = ['movie_id', 'title']
movies = pd.read_csv(movielenspath + 'movie_lens/u.item', sep='|', names=movie_columns, usecols=range(2), encoding="iso-8859-1")
# create one merged DataFrame
movie_ratings = pd.merge(movies, ratings)
movie_data = pd.merge(movie_ratings, users)
# Top rated movies
print("Top rated movies (overall): \n" , movie_data.groupby('title').size().sort_values(ascending=False)[:20])
print("\n")
# Find top rated movies for teenagers and old people
oldies = movie_data[(movie_data.age > 60)]
# Get the top rated ones
oldies = oldies.groupby('title').size().sort_values(ascending=False)
# Extract movies for teens
teens = movie_data[(movie_data.age > 12) & (movie_data.age < 20)]
# Get the top rated ones
teens = teens.groupby('title').size().sort_values(ascending=False)
print("Top ten movies for oldies: \n", oldies[:10])
print("\n")
print("Top ten movies for teens: \n", teens[:10])
print("\n")
ratings_by_title = movie_data.groupby('title').size()
popular_movies = ratings_by_title.index[ratings_by_title >= 250]
ratings_by_gender = movie_data.pivot_table('rating', index='title',columns='gender')
print("Rated movies by gender \n", ratings_by_gender.head())
print("\n")
ratings_by_gender = ratings_by_gender.loc[popular_movies]
top_movies_women = ratings_by_gender.sort_values(by='F', ascending=False)
print("Top rated movies by women \n", top_movies_women.head())
print("\n")
ratings_by_gender['diff'] = ratings_by_gender['M'] - ratings_by_gender['F']
gender_diff = ratings_by_gender['diff']
print("Difference by gender \n", ratings_by_gender.head())
print("\n")
# Only get absolute values
gender_diff = abs(gender_diff)
#Sort by size
gender_diff.sort_values(inplace=True,ascending = False)
# Show top 10 differences
gender_diff[:10].plot(kind='barh')
if not nogui:
plt.show()
return gender_diff[:10][0]
if __name__ == "__main__":
movie()
View File
Whitespace-only changes.
+35
View File
@@ -0,0 +1,35 @@
#! /usr/bin/python
import numpy as np
import matplotlib.pyplot as plt
salary = np.fromfile("salaries.txt", dtype=int, sep=",")
names = np.genfromtxt("names.txt", dtype='str', delimiter=",")
x = np.arange(len(names))
# Bar chart has to be with number on x axis, so we
# plot against x, but replace 'x' with names using 'xticks'
plt.bar(x, salary)
plt.xticks(x, names)
plt.ylabel("Salaries")
plt.xlabel("Names")
plt.title("Salary of 10 random people")
plt.show()
print(np.max(salary), np.min(salary), np.average(salary), np.median(salary))
salaries_new = salary[2:-2]
names_new = names[2:-2]
x = range(len(names_new))
plt.bar(x, salaries_new)
plt.xticks(x, names_new)
plt.show()
print(np.max(salaries_new), np.min(salaries_new), np.average(salaries_new))
+128
View File
@@ -0,0 +1,128 @@
{
"metadata": {
"name": "",
"signature": "sha256:79b0fcf6b10e48c62879c5ff2270f287ed3b43096d10407be6f805127c8fb2a2"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"This is an iPython Notebook. This part is plain text.\n"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print \"I can put in Python code\"\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"I can put in Python code\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"And graphs:\n",
" "
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%matplotlib inline"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"# Create x, randomly spaced between 0 to 20\n",
"x = np.linspace(0, 20, 1000)\n",
"y1 = np.sin(x)\n",
"y2 = np.cos(x)\n",
"# Plot the sin and cos functions\n",
"plt.plot(x , y1, \"-g\", label=\"sine\")\n",
"plt.plot(x , y2, \"-b\", label=\"cos\")\n",
"# The legend should be in the top right corner\n",
"plt.legend(loc=\"upper right\")\n",
"# Limit the y axis to -1.5 to 1.5\n",
"plt.ylim(-1.5, 1.5)\n",
"plt.show()\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAEACAYAAABfxaZOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnXlYVEfW/7/NDirIrrIjoHFD3HHFJWrUxJjEMSY6vjHJ\nbMkkmcn8JrPHzPtmsjhL9kwmMTGJjkuMGvcdlMUdREUURHYQF/ad7j6/P4pWlG7o5VbRDfV5nn5s\n+lbXud66/b1Vp06dAiQSiUQikUgkEolEIpFIJBKJRCKRSCQSiUQikUgkEolEIpFIJDbAlwDKAFww\ncDwOQBWAtNbXn8SclkQikUh4MAVADDoW/R3CzkYikUgkBrFToI5EABWdlFEpYEcikUgkFqKE6HcG\nAZgIIB3AHgBDBNiUSCQSCUdCYdi90weAW+v7hwBkiTghiUQikbTHQYCNmjbv9wL4BIAXgPK2hQYO\nHEg5OTkCTkcikUi6FTkAIowtLMK944+7Pv1xre/L7y+Uk5MDIpIvBV6vv/56l59Dd3rJ6ymvpzW/\nAAw0RZCV6OlvADANgA+AQgCvA3BsPfYZgCcA/ByAGkA9gCcVsCmRSCQSM1BC9Jd2cvzj1pdEIpFI\nuhgR7h2JYOLi4rr6FLoV8noqi7yeXYs1xc9Tq39KIpFIJEaiUqkAE7RcRPSORCKRmIWXlxcqKjpb\n+9kz8PT0RHl5uxgYk5E9fYlEYrWoVCpIXWAYuham9vSlT18ikUh6EFL0JRKJpAchRV8ikUh6EFL0\nJRKJRCHeeustPP/88119Gh0iJ3IlEonVIidy7yInciUSiURiMlL0JRKJxAzeeecdBAYGwt3dHYMH\nD8aRI0ewatUqLF++HACQl5cHOzs7fPPNNwgJCYGvry/+9re/3fk+EeHtt99GREQEfHx8sGTJEiFr\nEqToSyQSiYlcuXIFH3/8Mc6cOYPq6mocOHAAoaGhOlfLPSQnJyMrKwuHDx/GX//6V1y5cgUA8MEH\nH2DHjh04duwYSktL4enpiRdeeIH7ucsVuRKJxGZRvaHMtCS9btq8gb29PZqampCRkQFvb28EBwez\nevT43F9//XU4OztjxIgRiI6ORnp6OgYNGoR///vf+PjjjzFgwIA75UJCQrBu3TrY2fHrj0vRl0gk\nNoupYq0UEREReO+997Bq1SpkZGRgzpw5+Oc//6m3bL9+/e68d3NzQ21tLQAgPz8fixYtukfgHRwc\nUFZWhv79+3M7d+nekUgkEjNYunQpEhMTkZ+fD5VKhddee02ve8cQwcHB2LdvHyoqKu686uvruQo+\nIEVfIpFITCYrKwtHjhxBU1MTnJ2d4eLiAnt7e5Pq+NnPfoY//OEPKCgoAADcvHkTO3bs4HG69yBF\nXyKRSEykqakJv//97+Hr64v+/fvj1q1beOuttwDgnt5+Rz3/l19+GY888ghmz54Nd3d3xMbG4tSp\nU9zPXS7OkkgkVotcnHUXuThLIpFIJCYjRV8ikUh6EFL0JRKJpAchRV8ikUh6EFL0JRKJpAchRV8i\nkUh6EFL0JRKJpAchRV8ikUh6EFL0JRKJpAchRV8ikUh6EEqI/pcAygBc6KDMBwCyAaQDiFHApkQi\nkUjMQAnR/wrA3A6OzwMQASASwE8AfKqATYlEIulSCgsL8dhjj8HPzw8+Pj745S9/CSLC//3f/yE0\nNBT+/v5YsWIFqqurAQCNjY1YtmwZfHx84OnpiXHjxuHGjRvCz1sJ0U8E0NHGjo8A+Lr1/UkAfQH4\nK2BXIpFIugSNRoMFCxYgLCwM+fn5KCkpwZNPPomvvvoKX3/9NRISEnDt2jXU1tbixRdfBAB8/fXX\nqK6uRlFREcrLy/HZZ5/B1dVV+LmL8OkHAChs83cRgEABdiUSSTdHpVLmZSqnTp1CaWkpVq9eDVdX\nVzg5OWHSpElYv349Xn31VYSGhqJXr1546623sHHjRmg0Gjg5OeH27dvIzs6GSqVCTEwM+vTpo/xF\n6QRR2yXef1n15krdtQuYNw9QenvIuuY6rDu/DokFiSAQJgdNxvLo5ejt1FtZQ92Q27eBb74BTp0C\nnJyAmTOBH/0IcHFR1o5Gq8HWzK3Ye3UvaptrEdMvBitjVsK/txwUdkZDA7BxIxAfD6jVwPjxwIoV\nQN++ytohIhzJPYKtmVtRVleGKO8o/M/I/0GUd5Syhkw6p66xW1hYiJCQkHZ72ZaWliIkJOTO38HB\nwVCr1bhx4waWL1+OwsJCPPnkk6isrMSyZcvw5ptvwsFB7K61Inr6xQCC2vwd2PpZO557bhXCw1fh\n1VdXISEhQRHjifmJGPLJEOzL2YeZYTPxYPiDOJx7GA98/AAS8pSx0V3Zvh0YMgRISwPmzwemTAHW\nrQNGjgTOnVPOTk55DsZ+PhbvnXwPYwaMwcJBC5FXmYehnwzF2nNrlTPUDTlzBhgxAti8GZg2DXjo\nIeD0aWDwYNaJUoqKhgos3LgQL+x5AWGeYVg8ZDG0pMWkLyfhz0f+DI1Wo5wxGyAoKAgFBQXQaO79\nfw8YMAB5eXl3/i4oKICDgwP8/f3h4OCAv/zlL8jIyEBKSgp27dqFb775xmTbCQkJWLVq1Z1XVxEK\nw9E78wDsaX0/AcAJA+VIrSZatYooLIwoP58sZk/WHvJ915f2ZO1pd2z/1f3k+64v/XD5B8sNdUPW\nrCEaMIDo5Mn2x9avJ/L1JUpJsdxO5s1M6vf3fvTRyY9Iq9Xec+xC2QWK+CCC3kl6x3JD3ZBjx4h8\nfIg2b25/LCmJqF8/om+/tdxOeX05DftkGL205yVqUjfdc6y0ppSmfjWVfrztx6TWqC03dh9gmytZ\nHRqNhqKjo+k3v/kN1dXVUUNDAyUlJdEXX3xBkZGRlJubSzU1NfT444/T8uXLiYgoPj6ezp8/T2q1\nmm7fvk3R0dG0du1ao20auhYw4DnhyQYAJQCawXz3KwH8tPWl4yMAV8FCNkcZqOfOf2L1aqLhw4lq\nasxvlPPXz5Pvu76UXJBssMzp4tPk864PnS05a76hbsiRI0R+fkRZWYbL7N7NROXaNfPt3Ki9QeHv\nh9NXaV8ZLFNUVUSh74XSxgsbzTfUDcnJIfL3J9q/33CZjAzWjgkJ5ttpUjdR3No4emXvKwbL1DXX\n0ZQvp9AfD//RfEMGgJWKPhFRQUEBPfroo+Tt7U0+Pj708ssvk1arpb/+9a8UFBREvr6+tHz5cqqs\nrCQiog0bNtCgQYOoV69e5O/vTy+//DJpNBqj7Rm6FugC0VeKO/8JrZZoxQqin/7UvMaob66nqA+j\n6Nv0zrs5my5uovD3w6m2qdY8Y92MGzeYmBw61HnZf/yDaOJEIrUZHTytVksL/ruA/t+B/9dp2bTS\nNPJ514dyynNMN9QNaW4mGjWK6IMPOi+7fz9RQABRebl5tv54+I80b/28TnvxZbVlFPTPINp/tYOn\nkBnAikVfNIauBbqD6BMRVVYSBQd33JMxxG8P/JZ+9N2PjC7/1PdP0a/2/cp0Q92QpUuJXn3VuLIa\nDdHUqUz8TeXb9G9p+CfD27kLDPFO0js065tZ7VxAPZG33iJ68EHWOTKGF15gnShTOVN8hvxW+1FJ\ndYlR5fdm76XQ90KppsmCIfp93K8LPRlD1wLdRfSJmAshKor1bIwl40YG+b7rS2W1ZUZ/52bdTfJb\n7Ufp19ONN9QNOXCAKDycqK7O+O9kZxN5eRGVlhr/narGKvJf7U9nis8Y/Z0WTQuN+mwUrT+/3nhD\n3ZC8PHa9c3ON/05NDetAJSYa/x2tVkvjPx/foetNH8u2LqPfHvitSd/pCH260FPRdy1SS1K7l+hr\ntUSzZhF99JHxF+aRDY/Q35P/bvIFff/E+zRv/TyTv9dd0GiYy+C770z/7quvmuaK+/ORP9OPt/3Y\nZDvxufEU/n640aOD7siKFUR/NMN1/vXXRLGxxo8ONl/cTDH/jiGN1nifMxFRcXUxeb3jRUVVRaaf\npB706UJP5f5rkX49nfxX+3cv0SciSktjPmZjep/JBckU/K9gamhpMPmCNrY0Uth7YZSQa8Gslw2z\neTPR6NHGi0Jbbt9mUSQdTfzqKKstI693vCi/0rzwrLnr5tKHJz8067u2zsWLLGqqdV7QJNRqouho\nom3bjCirUVPEBxF0MOeg6YaIuVef3/G8Wd+9H0O60BO5/1o8uvFR+tfxf3U/0SciWriQ6EMjfucP\n//dh+vT0p2Zf1DWpa2jOt3PM/r6totUSjRhBtKd9ZKvR/OUvRM8b8Tv/0+E/0c92/sxsO6eLT1PQ\nP4OoWW2Cz6+bsHw58+eby/ffE40b1/mDffPFzRT7RazZdm7X3ybPtz2psKrQ7Dp0dKQLPY221yLz\nZib5rfajuua67in6x48ThYR07NvXXYT65nqzL2pjSyMN+McAOld6zuw6bJGDB4mGDDGvl6/j5k0i\nT0+ikg7m/GqbasnnXR/KumXEkKADpq+dblRkVneiqIhdX3OjcIhYbz8qquMQTq1WS2P/M5a2ZRox\nJOiAV/a+YlRkVmd0pAs9jbbX4rkfnqM3Et6483kXa7fZdPgfnjqVaGMHodrP73ieVsWvsvjCvpP0\nDi3busziemyJhx4i+uILy+v55S+Jfv97w8c/OPEBPbbpMYvt7MnaQyM+HdGjInlee43opZcsr+c/\n/yGaP9/w8YTcBIr6MMpkX/795FXkkdc7XlTVWGVRPZ6enjpR6/EvT09PIiIqqS4hz7c96VbdLSLq\nxqK/aRPR9On6j92qu0V93+5LN2pvWHSDEbHVhx5vedDNupsW12ULXLrE5kwaTJ8GaUdmJqurSc88\nq0aroYHvD+xwsZyxaLVaGvThIErKT7K4LlugtpbI29uyhXA66utZ9E9env7jizYusshF2pLine truncated
"text": [
"<matplotlib.figure.Figure at 0x54af3f0>"
]
}
],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"pwd"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 7,
"text": [
"u'C:\\\\Documents and Settings\\\\tiwaris\\\\My Documents\\\\IPython Notebooks'"
]
}
],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
+21
View File
@@ -0,0 +1,21 @@
#! /usr/bin/python
import numpy as np
import matplotlib.pyplot as plt
# Create x, evenly spaced between 0 to 20
x = np.linspace(0, 20, 1000)
y1 = np.sin(x)
y2 = np.cos(x)
# Plot the sin and cos functions
plt.plot(x , y1, "-g", label="sine")
plt.plot(x , y2, "-b", label="cos")
# The legend should be in the top right corner
plt.legend(loc="upper right")
# Limit the y axis to -1.5 to 1.5
plt.ylim(-1.5, 1.5)
plt.show()
+37
View File
@@ -0,0 +1,37 @@
#! /usr/bin/python
import numpy as np
def main():
x = [5,10,15,20,25]
# declare y as an empty list
y = []
# The not so good way
for counter in x:
y.append(counter / 5)
print("\nOld fashioned way: x = {} y = {} \n".format(x, y))
# The Pythonic way
# Using list comprehensions
z = [n/5 for n in x]
print("List Comprehensions: x = {} z = {} \n".format(x, z))
# Finally, numpy
try:
a = x / 5
except:
print("No, you can't do that with regular Python lists\n")
a = np.array(x)
b = a / 5
print("With Numpy: a = {} b = {} \n".format(a, b))
return "With Numpy: a = {} b = {} \n".format(a, b)
if __name__ == "__main__":
main()
+1
View File
@@ -0,0 +1 @@
Fluffy, John, Matt, James, Sarah, Jessica, Rupert, Pablo, Mr T, Bill Gates
+1
View File
@@ -0,0 +1 @@
0, 100, 200, 500, 1000, 1200, 1800, 1850, 5000, 10000
+4
View File
@@ -0,0 +1,4 @@
![Test badge](https://github.com/shantnu/PyEng/actions/workflows/main.yml/badge.svg)
Python for engineers -- Source code for the book https://www.pythonforengineers.com/python-for-scientists-and-engineers/
View File
Whitespace-only changes.
+10
View File
@@ -0,0 +1,10 @@
STRAY BIRDS
BY
RABINDRANATH TAGORE
STRAY birds of summer come to my
window to sing and fly away.
And yellow leaves of autumn, which
have no songs, flutter and fall there
with a sigh.
@@ -0,0 +1,14 @@
#! /usr/bin/python
f = open("birds.txt", "r")
data = f.read()
f.close()
lines = data.split("\n")
print("Wrong: The number of lines is", len(lines))
for l in lines:
if not l:
# Can also do this: if len(l) == 0
lines.remove(l)
print("Right: The number of lines is", len(lines))
+19
View File
@@ -0,0 +1,19 @@
#! /usr/bin/python
f = open("birds.txt", "r")
data = f.read()
f.close()
words = data.split(" ")
print("The words in the text are:")
print(words)
num_words = len(words)
print("The number of words is ", num_words)
lines = data.split("\n")
print("The lines in the text are:")
print(lines)
print("The number of lines is", len(lines))
+7
View File
@@ -0,0 +1,7 @@
#!/usr/bin/python
f = open("birds.txt", "r")
data = f.read()
f.close()
print(data)
+32
View File
@@ -0,0 +1,32 @@
#! /usr/bin/python
import sys
def count_words(data):
words = data.split(" ")
num_words = len(words)
return num_words
def count_lines(data):
lines = data.split("\n")
for l in lines:
if not l:
lines.remove(l)
return len(lines)
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python word_count.py <file>")
exit(1)
filename = sys.argv[1]
f = open(filename, "r")
data = f.read()
f.close()
num_words = count_words(data)
num_lines = count_lines(data)
print("The number of words: ", num_words)
print("The number of lines: ", num_lines)
+40
View File
@@ -0,0 +1,40 @@
import numpy as np
import wave
import struct
def create_wav():
# frequency is the number of times a wave repeats a second
frequency = 1000
num_samples = 48000
# The sampling rate of the analog to digital convert
sampling_rate = 48000.0
amplitude = 16000
file = "test.wav"
sine_wave = [np.sin(2 * np.pi * frequency * x/sampling_rate) for x in range(num_samples)]
# Optional: Uncomment the code below to draw a graph.
#x = range(num_samples)
#plt.plot(x[:300], sine_wave[:300])
#plt.show()
nframes=num_samples
comptype="NONE"
compname="not compressed"
nchannels=1
sampwidth=2
wav_file=wave.open(file, 'w')
wav_file.setparams((nchannels, sampwidth, int(sampling_rate), nframes, comptype, compname))
for s in sine_wave:
wav_file.writeframes(struct.pack('h', int(s*amplitude)))
wav_file.close()
if __name__ == "__main__":
create_wav()
+41
View File
@@ -0,0 +1,41 @@
#! /usr/bin/python
import numpy as np
import wave
import struct
import matplotlib.pyplot as plt
def get_freq(nogui = False):
frame_rate = 48000.0
infile = "test.wav"
num_samples = 48000
wav_file = wave.open(infile, 'r')
data = wav_file.readframes(num_samples)
wav_file.close()
data = struct.unpack('{n}h'.format(n=num_samples), data)
data = np.array(data)
data_fft = np.fft.fft(data)
# This will give us the frequency we want
frequencies = np.abs(data_fft)
print("The frequency is {} Hz".format(np.argmax(frequencies)))
if nogui:
return np.argmax(frequencies)
else:
plt.subplot(2,1,1)
plt.plot(data[:300])
plt.title("Original audio wave")
plt.subplot(2,1,2)
plt.plot(frequencies)
plt.title("Frequencies found")
plt.xlim(0,1200)
plt.savefig('wave.png')
plt.show()
if __name__ == "__main__":
get_freq()
+107
View File
@@ -0,0 +1,107 @@
#! /usr/bin/python
import numpy as np
import wave
import struct
import matplotlib.pyplot as plt
def noisy(nogui = False):
# frequency is the number of times a wave repeats a second
frequency = 1000
noisy_freq = 50
num_samples = 48000
# The sampling rate of the analog to digital convert
sampling_rate = 48000.0
#Create the sine wave and noise
sine_wave = [np.sin(2 * np.pi * frequency * x1 / sampling_rate) for x1 in range(num_samples)]
sine_noise = [np.sin(2 * np.pi * noisy_freq * x1/ sampling_rate) for x1 in range(num_samples)]
#Convert them to numpy arrays
sine_wave = np.array(sine_wave)
sine_noise = np.array(sine_noise)
# Add them to create a noisy signal
combined_signal = sine_wave + sine_noise
if not nogui:
plt.subplot(3,1,1)
plt.title("Original sine wave")
# Need to add empty space, else everything looks scrunched up!
plt.subplots_adjust(hspace=.5)
plt.plot(sine_wave[:500])
plt.subplot(3,1,2)
plt.title("Noisy wave")
plt.plot(sine_noise[:4000])
plt.subplot(3,1,3)
plt.title("Original + Noise")
plt.plot(combined_signal[:3000])
plt.show()
data_fft = np.fft.fft(combined_signal)
freq = (np.abs(data_fft[:len(data_fft)]))
if not nogui:
plt.plot(freq)
plt.title("Before filtering: Will have main signal (1000Hz) + noise frequency (50Hz)")
plt.xlim(0,1200)
plt.show()
filtered_freq = []
index = 0
result = 0,0
for f in freq:
# Filter between lower and upper limits
# Choosing 950, as closest to 1000. In real world, won't get exact numbers like these
if index > 950 and index < 1050:
# Has a real value. I'm choosing >1, as many values are like 0.000000001 etc
if f > 1:
filtered_freq.append(f)
result = f,index
else:
filtered_freq.append(0)
else:
filtered_freq.append(0)
index += 1
if not nogui:
plt.plot(filtered_freq)
plt.title("After filtering: Main signal only (1000Hz)")
plt.xlim(0,1200)
plt.show()
plt.close()
recovered_signal = np.fft.ifft(filtered_freq)
if not nogui:
plt.subplot(3,1,1)
plt.title("Original sine wave")
# Need to add empty space, else everything looks scrunched up!
plt.subplots_adjust(hspace=.5)
plt.plot(sine_wave[:500])
plt.subplot(3,1,2)
plt.title("Noisy wave")
plt.plot(combined_signal[:4000])
plt.subplot(3,1,3)
plt.title("Sine wave after clean up")
plt.plot((recovered_signal[:500]))
else:
return result
plt.show()
if __name__ == "__main__":
noisy()
+59
View File
@@ -0,0 +1,59 @@
import sys
import numpy as np
import ast
import json
def find_correlation(movie_list, movie_for_correlation):
'''
Input:
movie_list - List of movies
movie_for_correlation: The movie to calculate the correlation for
Return:
Dictionary of correlation for movie_for_correlation
'''
correlate_dict = {}
for movie in movie_list:
# Don't include current movie in correlation, as you can't compare a movie to itself!
if movie != movie_for_correlation:
movie_for_correlation_list = []
movie_to_compare_list = []
# Loop through the people who reviewed the movie
for reviewer_name in movie_list[movie_for_correlation]:
# Check that the reviewer has reviewed the current movie.
# If so, calculate the correlation coefficient.
# If they haven't reviewed the movie, then it makes no sense doing a correlation.
if reviewer_name in movie_list[movie]:
movie_for_correlation_list.append(movie_list[movie_for_correlation][reviewer_name])
movie_to_compare_list.append(movie_list[movie][reviewer_name])
correlate_dict[movie] = np.corrcoef(movie_for_correlation_list,movie_to_compare_list)[1][0]
return correlate_dict
def main(infile):
with open(infile, 'r') as f:
temp = f.read()
movies_list = ast.literal_eval(temp)
print(movies_list)
correlated_dict = {}
for movie in movies_list:
correlated_dict[movie] = find_correlation(movies_list, movie)
print(correlated_dict)
json.dump(correlated_dict, open("corr_dict.py",'w'))
return correlated_dict
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: python calc_correlation.py <data file.py>")
exit(1)
main(sys.argv[1])
+1
View File
@@ -0,0 +1 @@
{"Terminator": {"Terminator 2": 0.9986154372037583, "It happened one night": 0.10629880069054676, "27 Dresses": -0.15404159684748153, "Poirot": 0.9113223768657669, "Sherlock Holmes": 0.7702079842374077}, "Terminator 2": {"Terminator": 0.9986154372037583, "It happened one night": 0.13468700594029476, "27 Dresses": -0.12547286652195427, "Poirot": 0.9072647087265547, "Sherlock Holmes": 0.738895769518175}, "It happened one night": {"Terminator": 0.10629880069054676, "Terminator 2": 0.13468700594029476, "27 Dresses": 0.5791405068790082, "Poirot": 0.2895702534395041, "Sherlock Holmes": 0.0}, "27 Dresses": {"Terminator": -0.1540415968474815, "Terminator 2": -0.12547286652195427, "It happened one night": 0.5791405068790082, "Poirot": -0.3043478260869565, "Sherlock Holmes": -0.27583864218368526}, "Poirot": {"Terminator": 0.911322376865767, "Terminator 2": 0.9072647087265548, "It happened one night": 0.2895702534395041, "27 Dresses": -0.3043478260869565, "Sherlock Holmes": 0.6698938453032356}, "Sherlock Holmes": {"Terminator": 0.7702079842374077, "Terminator 2": 0.738895769518175, "It happened one night": 0.0, "27 Dresses": -0.27583864218368526, "Poirot": 0.6698938453032355}}
+38
View File
@@ -0,0 +1,38 @@
{'Terminator': {'Tom': 4.0,
'Jack': 1.5,
'Lisa': 3.0,
'Sally': 2.0},
'Terminator 2': {'Tom': 5.0,
'Jack' : 1.0,
'Lisa': 3.5,
'Sally': 2.0},
'It happened one night': {'Tom': 3.5,
'Jack': 3.5,
'Tiger': 4.0,
'Lisa': 5.0,
'Michele': 3.0,
'Sally': 4.0,},
'27 Dresses': {'Tom': 3.0,
'Jack': 3.5,
'Tiger': 3.0,
'Lisa': 5.0,
'Michele': 4.0,
'Sally': 4.0},
'Poirot': {'Tom': 4.0,
'Jack': 3.0,
'Tiger': 5.0,
'Lisa': 4.0,
'Michele': 3.5,
'Sally': 3.0,
},
'Sherlock Holmes': {'Tom': 4.0,
'Jack': 3.0,
'Tiger': 3.5,
'Lisa': 3.5,
'Sally': 2.0,
}}
+60
View File
@@ -0,0 +1,60 @@
import pdb
import json
def main():
# My ratings for movies.
my_movies = {'Terminator': 5.0,
'Sherlock Holmes' : 4.0,
'Poirot' : 4.5
}
# Read the data from the correlation dictionary we calculated earlier
correlated_dict = json.load(open("corr_dict.py"))
# A dictionary to store the total of my calculated votes
total_my_votes = {}
# A running total to store intermediate results.
running_total = 0
# Loop over rated movies
for movie_key in my_movies.keys():
# Loop over the dictionary of correlation coefficients
for movie_to_compare in correlated_dict[movie_key]:
running_total = 0
# If it is not a movie I have rated, we can calculate the correlation
if movie_to_compare not in my_movies.keys():
# If this is the first time we are running the code, we won't have anything stored.
# In that case, create a new dictionary element.
if movie_to_compare not in total_my_votes:
# Line below creates a new dictionary element for total_my_votes and gives it a value.
total_my_votes.setdefault(movie_to_compare, (correlated_dict[movie_key][movie_to_compare] * my_movies[movie_key]) )
else:
# If this is not the first time, merely update the values we have created before
total_my_votes[movie_to_compare] += correlated_dict[movie_key][movie_to_compare] * my_movies[movie_key]
print("total_my_votes = ", total_my_votes)
recommended_movies = {}
for movie_key in total_my_votes.keys():
recommended_movies[movie_key] = total_my_votes[movie_key] / len(total_my_votes.keys())
print(recommended_movies)
for movie_key in recommended_movies:
if recommended_movies[movie_key] > 3.0:
print("Strongly recommended for you: ", movie_key)
elif recommended_movies[movie_key] > 0.0:
print("Recommended for you: ", movie_key)
else :
print("Not recommended: ", movie_key)
return recommended_movies
if __name__ == '__main__':
main()
+19
View File
@@ -0,0 +1,19 @@
attrs>=21.2.0
cycler>=0.10.0
iniconfig>=1.1.1
kiwisolver>=1.3.1
matplotlib>=3.4.2
numpy>=1.20.3
opencv-python>=4.5.2.52
packaging>=20.9
pandas>=1.2.4
Pillow>=8.2.0
pluggy>=0.13.1
py>=1.10.0
pyparsing>=2.4.7
pytest>=6.2.4
python-dateutil>=2.8.1
pytz>=2021.1
six>=1.16.0
toml>=0.10.2
xlrd>=2.0.1
+18
View File
@@ -0,0 +1,18 @@
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Hello World!"
@app.route("/<string:name>")
def hello_name(name):
hello = "Hello " + name
return hello
# For the RPI
#app.run(host='0.0.0.0', port=80, debug=True)
# For testing on a normal Pc
app.run(debug=True)
Loaded 100 of 154 files, more files were not shown because too many files have changed in this diff. Show more