-
Notifications
You must be signed in to change notification settings - Fork 0
/
sma2-upload-to-pvoutputorg
executable file
·198 lines (161 loc) · 6.85 KB
/
sma2-upload-to-pvoutputorg
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#! /usr/bin/env python
#
# sma2-upload-to-pvoutputorg - Upload generation history to pvoutput.org
# Copyright (C) 2014 Peter Barker <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from __future__ import print_function
import argparse
import datetime
from datetime import date
import sys
import time
import smadata2.protocol
import smadata2.util
import smadata2.config
import smadata2.db
import smadata2.pvoutputuploader
def getmissing(args):
config = smadata2.config.SMAData2Config()
db = config.database()
for system in config.systems():
mypvoutput = config.pvoutput_connect(system)
uploader = smadata2.pvoutputuploader.PVOutputUploader(db, system,
mypvoutput)
uploader.setVerbose(1)
allmissing = uploader.getmissing(args.fromdate.somedate, args.todate.somedate)
for missing in allmissing:
print(missing)
def getstatus(args):
config = smadata2.config.SMAData2Config()
db = config.database()
for system in config.systems():
mypvoutput = config.pvoutput_connect(system)
uploader = smadata2.pvoutputuploader.PVOutputUploader(db, system,
mypvoutput)
uploader.setVerbose(1)
if args.fromdate:
fromdatetime = args.fromdate.somedatetime;
else:
fromdatetime = None
allstatus = uploader.getstatus(fromdatetime, 1)
for status in allstatus:
print(status)
def upload_unuploaded(args):
config = smadata2.config.SMAData2Config()
db = config.database()
for system in config.systems():
mypvoutput = config.pvoutput_connect(system)
uploader = smadata2.pvoutputuploader.PVOutputUploader(db, system,
mypvoutput)
uploader.setVerbose(1)
print("Uploading unuploaded statuses for %s" % (system.name))
uploader.upload_unuploaded_statuses()
def addoutput(args):
config = smadata2.config.SMAData2Config()
db = config.database()
mypvoutput = config.pvoutput_connect(args.sid.system)
uploader = smadata2.pvoutputuploader.PVOutputUploader(db,
args.sid.system,
mypvoutput)
uploader.setVerbose(1)
print("Uploading unuploaded statuses for %s" % args.sid.system)
uploader.addoutput(args.fordate.somedate, args.generated)
class dateType():
def __init__(self, param):
self.somedate = datetime.datetime.strptime(param, '%Y%m%d')
def __call__(self):
print("__called__ called on dateType?!")
class datetimeType():
def __init__(self, param):
self.somedatetime = datetime.datetime.strptime(param, '%Y%m%d %H:%M')
def __call__(self):
print("__called__ called on datetimeType?!")
class sidType():
def __init__(self, param):
config = smadata2.config.SMAData2Config()
self.system = None
for system in config.systems():
if str(system.pvoutput_sid) == str(param):
self.system = system
break
if self.system is None:
fatal("sid not found")
def __call__(self):
print("__called__ called on datetimeType?!")
parser = argparse.ArgumentParser(description='Work with pvoutput and smadata')
subparsers = parser.add_subparsers()
uu_parser = subparsers.add_parser('upload-unuploaded')
uu_parser.set_defaults(func=upload_unuploaded)
getmissing_parser = subparsers.add_parser(
'get-missing',
help="Get missing daily production dates")
getmissing_parser.add_argument('--from', type=dateType, dest='fromdate')
getmissing_parser.add_argument('--to', type=dateType, dest='todate')
getmissing_parser.set_defaults(func=getmissing)
getstatus_parser = subparsers.add_parser(
'get-status',
help='Get live status of system')
getstatus_parser.add_argument('--from', type=datetimeType, dest='fromdate')
getstatus_parser.add_argument('--count', type=int)
getstatus_parser.set_defaults(func=getstatus)
addoutput_parser = subparsers.add_parser(
'add-output',
help='Add a daily output to pvoutput.org')
addoutput_parser.add_argument('sid', type=sidType, help="system id")
addoutput_parser.add_argument('fordate', type=dateType)
addoutput_parser.add_argument('--generated', type=int,
help="delta production for day")
addoutput_parser.set_defaults(func=addoutput)
args = parser.parse_args()
args.func(args)
sys.exit(0)
config = smadata2.config.SMAData2Config()
db = config.database()
for system in config.systems():
mypvoutput = config.pvoutput_connect(system)
uploader = smadata2.pvoutputuploader.PVOutputUploader(db, system, mypvoutput)
uploader.setVerbose(1)
# stuff below this line is useful for fixing data on the server - and
# working out what needs fixing....
if False:
print("Showing production datapoints for %s" % system)
uploader.show_production_for_datapoint("20141029", "19:15")
uploader.show_production_for_datapoint("20141029", "19:20")
uploader.show_production_for_datapoint("20141029", "19:25")
uploader.show_production_for_datapoint("20141029", "19:30")
uploader.show_production_for_datapoint("20141030", "06:30")
uploader.show_production_for_datapoint("20141030", "06:35")
uploader.show_production_for_datapoint("20141030", "06:40")
if False:
somedate = "20141031"
print("reconciling data for system=%s date=%s" % (system, somedate))
pvodate = mypvoutput.parse_date_and_time(somedate, '00:00')
uploader.reconcile_date(pvodate)
if False:
somedate = "20141031"
print("uploading data for date=%s system=%s" % (system, somedate))
pvodate = mypvoutput.parse_date_and_time(somedate, '00:00')
uploader.upload_statuses_for_day(pvodate)
if False:
print("reconciling all data for system %s" % (system))
uploader.reconcile()
if False:
# untested:
date = "20141104"
fix = True
print("doing date %s" % (system))
uploader.do_date(date, fix)
sys.exit(0)