This repository has been archived by the owner on May 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
156 lines (105 loc) · 4.42 KB
/
example.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# -*- coding: utf-8 -*-
__author__ = 'XaviTorello'
from orakwlum.consumption import *
from orakwlum.datasource import *
from orakwlum.prediction import *
from orakwlum.proposal import *
from orakwlum.importer import *
import logging
from datetime import datetime
from multiprocessing.dummy import Pool as ThreadPool
import glob, os
def Consumption_tester():
consum = Consumption("ES0031406229285001HS0F", 2016, 3, 2, 15)
print "{} - {}: {} / {}".format(consum.cups.number, consum.hour,
consum.consumption_real,
consum.consumption_proposal)
def Datasource_tester():
dades = Mongo(user="orakwlum", db="orakwlum")
#dades.test_data(drop=True)
agg = "hour"
sum = ["consumption_real", "consumption_proposal"]
agregant_per_hores = dades.aggregate_sum(field_to_agg=agg,
fields_to_sum=sum)
#agregant_per_hores = dades.aggregate_count_fields(field_to_agg=agg,fields_to_count=sum)
print "{} elements aggregating by '{}':".format(
len(agregant_per_hores), agg)
for entrada in agregant_per_hores:
for camp in entrada.iteritems():
print " {}, sum: {} / {}".format(
entrada['_id'], entrada['sum_consumption_real'],
entrada['sum_consumption_proposal'])
def History_tester():
date_start = datetime(2016, 3, 01)
date_end = datetime(2016, 3, 3)
history = History(start_date=date_start, end_date=date_end)
#history.dump_history()
history.load_consumption_hourly()
history.dump_history_hourly()
insert_example = {"cups": "ES0031300798436013HSx0F",
"consumption_real": 550,
"consumption_proposal": 179,
"hour": datetime(2016, 03, 01, 01, 00)}
history.upsert_consumption(values=insert_example)
def Prediction_tester():
date_start = datetime(2016, 3, 01)
date_end = datetime(2016, 3, 2)
cups_to_filter = None
prediction = Prediction(start_date=date_start,
end_date=date_end,
filter_cups=cups_to_filter,
compute=True)
def Proposal_tester():
date_start = datetime(2015, 12, 04)
date_end = datetime(2015, 12, 05)
cups_to_filter = None
proposal = Proposal(start_date=date_start,
end_date=date_end,
filter_cups=cups_to_filter,
compute=True,
collection=COLLECTION)
proposal.add_new_scenario(name="Original projection",
type="base",
collection_name="base")
proposal.add_new_scenario(name="CUPS increased",
type="cups_increased",
collection_name="cups_WTF")
proposal.add_new_scenario(name="CUPS erased",
type="cups_erased",
collection_name="cups_erased")
proposal.add_new_scenario(name="Margin +15%",
type="margin",
collection_name="margin")
proposal.render_scenarios()
proposal.show_proposal()
def Sampledata_tester():
dades = Mongo(user="orakwlum", db="orakwlum")
dades.test_data(drop=True, collection="dataset")
def Import_tester():
os.chdir("/opt/srcs/abe/abe_f1_comer_706/2015-01-Mes/0706/")
files = glob.glob("*.xml")
max = len(files)
for idx, file in enumerate(files):
if idx < 149:
continue
print "{}/{} Procesing F1 '{}'".format(idx + 1, max, file)
importer = F1Importer(file, "import")
#print "Type: {}".format(importer.type)
#print "Count: {}".format(importer.invoices_count)
invoices = importer.invoices
importer.process_consumptions()
def Import_testerLiteF1():
importer = F1Importer("./testDataF1.xml", collection="rolf")
print "Type: {}".format(importer.type)
print "Count: {}".format(importer.invoices_count)
invoices = importer.invoices
importer.process_consumptions()
def Import_testerLiteQ1():
importer = Q1Importer("./testDataQ1.xml", collection="rolf")
print "Type: {}".format(importer.type)
comptadors = importer.lectures
importer.process_consumptions()
COLLECTION = "importer_test2"
logging.basicConfig(level=logging.DEBUG)
#Sampledata_tester()
Proposal_tester()