-
Notifications
You must be signed in to change notification settings - Fork 11
/
samples_count_by_month.py
62 lines (57 loc) · 1.76 KB
/
samples_count_by_month.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- coding: UTF-8 -*-.
import argparse
import csv
import datetime
def params():
parser = argparse.ArgumentParser()
parser.add_argument('input_csv', help='Input CSV Location')
params = parser.parse_args()
return params.input_csv
def update_counter(counter, key):
if key in counter:
counter[key] += 1
else:
counter[key] = 1
counter_gw = {}
counter_mw = {}
# get params
input_csv = params()
with open(input_csv, 'rb') as file:
reader = csv.DictReader(file)
for row in reader:
# convert timestamp
time = datetime.datetime.fromtimestamp(float(row["Time"]))
year = int(time.strftime('%Y'))
if year < 2013:
if row["Label"] == "1":
update_counter(counter_mw, "<2013")
else:
update_counter(counter_gw, "<2013")
else:
if year > 2017:
if row["Label"] == "1":
update_counter(counter_mw, ">2017")
else:
update_counter(counter_gw, ">2017")
else :
time = time.strftime('%m.%Y')
if row["Label"] == "1":
update_counter(counter_mw, time)
else:
update_counter(counter_gw, time)
# write table
print "Year\tGoodware\tMalware"
print "<2013\t" + str(counter_gw["<2013"]) + "\t0"
for y in range(2013,2018):
for m in range(1,13):
my = str(m).zfill(2)+"."+str(y)
if my in counter_gw:
gw = counter_gw[my]
else:
gw = 0
if my in counter_mw:
mw = counter_mw[my]
else:
mw = 0
print my + "\t" + str(gw) + "\t" + str(mw)
print ">2017\t" + str(counter_gw[">2017"]) + "\t" + str(counter_mw[">2017"])