usr bin env python coding utf-8 import tango import tango thirdparty s

  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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import tango
import tango.thirdparty.simplejson as json
import urllib
import pickle
from datetime import datetime, timedelta
from os import listdir, stat, remove
jsonSrvURL = "http://10.1.110.201:8080/expones"
#dumpPath = "dumps"
dumpPath = "%s/%s/dumps" % (tango.PROJECT_ROOT, tango.PROJECT_NAME)
dumpExpire = 1 # дней
imagePath = ""
atps = {
"1":"АТП Батайск",
"2":"АТП Иваново",
"3":"АТП Кропоткин",
"4":"АТП Орел",
"5":"АТП Энгельс",
"6":"АТП Тверь",
"7":"АТП Тольятти",
"8":"АТП Челябинск"
}
cars = {
"all":"все",
"mazt":"МАЗ-Тягач",
"mazp":"МАЗ-Прицеп",
"man":"МАН",
"ren":"RENAULT",
"sch":"SCHMITZ"
}
typeNom = {
"total":"все",
"totalwdtp":"все без ДТП",
"bus":"Автошины",
"battery":"Аккумуляторы",
"dtps":"ДТП",
"other":"ЗЧ",
"otherwdtp":"ЗЧ без ДТП",
}
graphs = {
"total" :"Всего расходов",
"totalByCar" :"Расход на 1 ам",
"totalByCarMaz":"Расход на 1 МАЗ",
"totalByCarMan":"Расход на 1 МАН",
"totalByCarRen":"Расход на 1 RENAULT",
"totalByCarSch":"Расход на 1 Shmitz",
}
## всопмогательная функция итерации по промежутку дат
def dateRange(begin, end, delta = timedelta(1)):
if not isinstance(delta, timedelta):
delta = timedelta(delta)
ZERO = timedelta(0)
if begin < end:
if delta <= ZERO:
raise StopIteration
test = end.__gt__
else:
if delta >= ZERO:
raise StopIteration
test = end.__lt__
while test(begin):
yield begin
begin += delta
def checkOldFiles(expire=1):
now = datetime.now()
for i in listdir(dumpPath):
f = datetime.fromtimestamp(int(stat("%s/%s" % (dumpPath,i)).st_mtime))
if (now-f).days >= expire:
remove("%s/%s" % (dumpPath,i))
###
def checkData(d1,d2,atp):
checkOldFiles(dumpExpire)
try:
f = open("%s/%s-%s-%s.dat.pk" % (dumpPath, d1, d2, atp), "rb")
return pickle.load(f)
except:
return False
return False
###
def checkCCountData(d1,d2,atp):
try:
f = open("%s/%s-%s-%s.dcc.pk" % (dumpPath, d1, d2, atp), "rb")
return pickle.load(f)
except:
return False
return False
###
def getData(d1,d2,atp):
data = checkData(d1,d2,atp)
if data != False:
return data
else:
params = urllib.urlencode({"par1":d1,"par2":d2,"atp":atps[atp]})
ret = json.loads("".join(urllib.urlopen("%s/outlay?%s" % (jsonSrvURL, params), proxies={}).readlines()))
if len(ret) > 0:
f = open("%s/%s-%s-%s.dat.pk" % (dumpPath, d1, d2, atp), "wb")
pickle.dump(ret, f)
f.close()
return ret
###