File Coverage

ToNumber.xs
Criterion Covered Total %
statement 22 22 100.0
branch 4 6 66.6
condition n/a
subroutine n/a
pod n/a
total 26 28 92.8


line stmt bran cond sub pod time code
1             #include "EXTERN.h"
2             #include "perl.h"
3             #include "XSUB.h"
4              
5             #include
6             #include
7             #include
8             #include
9              
10             static void
11 8           parse_suricata_week(const char *timestamp, double *sin_out, double *cos_out)
12             {
13 8           int year = 0, mon = 0, mday = 0, h = 0, m = 0;
14 8           double s = 0.0;
15             double week_seconds, angle;
16             struct tm tm;
17              
18 8           memset(&tm, 0, sizeof(struct tm));
19 8           sscanf(timestamp, "%4d-%2d-%2dT%d:%d:%lf",
20             &year, &mon, &mday, &h, &m, &s);
21              
22 8           tm.tm_year = year - 1900;
23 8           tm.tm_mon = mon - 1;
24 8           tm.tm_mday = mday;
25 8           tm.tm_isdst = -1;
26 8           mktime(&tm);
27              
28 8           week_seconds = tm.tm_wday * 86400.0 + h * 3600.0 + m * 60.0 + s;
29 8           angle = 6.28318530717958647692528 * week_seconds / 604800.0;
30              
31 8           *sin_out = sin(angle);
32 8 100         if (cos_out != NULL)
33 4           *cos_out = cos(angle);
34 8           }
35              
36             MODULE = Algorithm::Time::ToNumber PACKAGE = Algorithm::Time::ToNumber
37              
38             void
39             suricata_to_circle_both(class, timestamp)
40             SV *class
41             char *timestamp
42             PREINIT:
43             double sin_val;
44             double cos_val;
45             PPCODE:
46             (void)class;
47 4           parse_suricata_week(timestamp, &sin_val, &cos_val);
48 4 50         EXTEND(SP, 2);
49 4           PUSHs(sv_2mortal(newSVnv(sin_val)));
50 4           PUSHs(sv_2mortal(newSVnv(cos_val)));
51              
52             double
53             suricata_to_angle_both(class, timestamp)
54             SV *class
55             char *timestamp
56             PREINIT:
57             double sin_val;
58             CODE:
59             (void)class;
60 4           parse_suricata_week(timestamp, &sin_val, NULL);
61 4 50         RETVAL = sin_val;
62             OUTPUT:
63             RETVAL