Skip to content

Instantly share code, notes, and snippets.

@winfredraj
Created July 29, 2023 14:56
Show Gist options
  • Save winfredraj/55bbd5d4f95c4b5942400695aa8c93b5 to your computer and use it in GitHub Desktop.
Save winfredraj/55bbd5d4f95c4b5942400695aa8c93b5 to your computer and use it in GitHub Desktop.
class DateTimemilli is DateTime {
has Int $.millisecond;
method gist()
{
self.Str~":"~$.millisecond.Str;
}
multi sub infix:«>»(DateTimemilli:D $a, DateTimemilli:D $b --> Bool:D)
{
say $a;
say $b;
return False;
}
}
sub test(%acc,%from_seq)
{
my $fh = open "outcan_wechseldurchmesser.csv", :a;
say %acc;
my @key = %from_seq.keys.grep(/yyyy/);
my $next_date = Dater.parse(%from_seq{@key[0]}, actions => Dater_class).made;
my $acc_date = Dater.parse(%acc{@key[0]}, actions => Dater_class).made;
say $next_date~"-------------"~$acc_date;
if ($acc_date.year == 1900)
{
$acc_date = $next_date;
}
while ($acc_date < $next_date)
{
$fh.say($acc_date~"\t"~%acc<value>);
$acc_date = $acc_date.later(:1seconds);
say $acc_date;
}
$fh.close;
return %from_seq;
}
sub make_hash(%acc, %from_seq)
{
my $key = %from_seq<event@rtc(yyyy/mm/dd-hh:mm:ss)>~":"~%from_seq<ticks(ms)>;
%acc{$key}.append(%from_seq<name> => %from_seq<value>);
return %acc;
}
sub MAIN()
{
my $parser-options = CSV-STRICT +| CSV-EMPTY-IS-NULL;
my Text::CSV::LibCSV $parser .=new(:$parser-options, :delimiter(';') :auto-decode('utf8'), :has-headers);
my @lines_from_file = $parser.read-file('Problem_roll_change_2.csv');
my @variables = @lines_from_file.map(->%a {%a<name>}).unique;
# my %hash_time = @lines_from_file.map(->%a {&make_hash(%a)});
my @lines_from_file_first_10000 = @lines_from_file[^10000];
my %time_hash;
reduce &make_hash, %time_hash,|@lines_from_file_first_10000;
say %time_hash.keys.sort.head;
my $testdate = DateTimemilli.new(year => 2000, month => 12, day => 12, hour =>12, minute =>23 , second => 45, millisecond => 9999);
my $testdate1 = DateTimemilli.new(year => 2002, month => 12, day => 12, hour =>12, minute =>23 , second => 45, millisecond => 9999);
#say $testdate;
say ($testdate1>$testdate);
#my @lines = @lines_from_file.grep(->%a {%a<name>~~/.*rw1\.rampen.*/});
#reduce &test, @lines[0], |@lines;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment