rda-python-metrics 1.0.22__py3-none-any.whl → 1.0.23__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of rda-python-metrics might be problematic. Click here for more details.

@@ -25,10 +25,11 @@ from rda_python_common import PgDBI
25
25
  from . import PgIPInfo
26
26
 
27
27
  # the define options for gathering ipinfo data
28
+ DATES = 0x01 # fix data usages for given dates
28
29
  MONTH = 0x02 # fix data usages for given months
29
30
  YEARS = 0x04 # fix data usages for given years
30
31
  NDAYS = 0x08 # fix data usages in recent number of days
31
- MULTI = (MONTH|YEARS)
32
+ MULTI = (DATES|MONTH|YEARS)
32
33
  SINGL = (NDAYS)
33
34
 
34
35
  IPINFO = {
@@ -49,8 +50,10 @@ def main():
49
50
  for arg in argv:
50
51
  if arg == "-b":
51
52
  PgLOG.PGLOG['BCKGRND'] = 1
52
- elif re.match(r'^-[mNy]$', arg) and option == 0:
53
- if arg == "-m":
53
+ elif re.match(r'^-[dmNy]$', arg) and option == 0:
54
+ if arg == "-d":
55
+ option = DATES
56
+ elif arg == "-m":
54
57
  option = MONTH
55
58
  elif arg == "-y":
56
59
  option = YEARS
@@ -74,17 +77,6 @@ def main():
74
77
  PgDBI.dssdb_dbname()
75
78
  PgLOG.cmdlog("fillipinfo {}".format(' '.join(argv)))
76
79
 
77
- if option&NDAYS:
78
- curdate = IPINFO['CDATE']
79
- datelimit = PgUtil.adddate(curdate, 0, 0, -int(inputs[0]))
80
- option = MONTH
81
- inputs = []
82
-
83
- while curdate >= datelimit:
84
- tms = curdate.split('-')
85
- inputs.append("{}-{}".format(tms[0], tms[1]))
86
- curdate = PgUtil.adddate(curdate, 0, 0, -int(tms[2]))
87
-
88
80
  fill_ip_info(option, inputs, table)
89
81
 
90
82
  sys.exit(0)
@@ -95,35 +87,48 @@ def main():
95
87
  def fill_ip_info(option, inputs, table):
96
88
 
97
89
  cntall = 0
98
- date = None
90
+ func = eval('fix_{}_records'.format(table))
99
91
  for input in inputs:
100
92
  if option&NDAYS:
101
93
  edate = IPINFO['CDATE']
102
- date = PgUtil.adddate(edate, 0, 0, -int(input))
94
+ date = PgUtil.adddate(edate, 0, 0, -int(input))
95
+ elif option&DATES:
96
+ edate = date = input
103
97
  elif option&MONTH:
104
98
  tms = input.split('-')
105
99
  date = "{}-{:02}-01".format(tms[0], int(tms[1]))
106
100
  edate = PgUtil.enddate(date, 0, 'M')
107
- elif option&YEARS:
101
+ else:
108
102
  date = input + "-01-01"
109
103
  edate = input + "-12-31"
110
-
111
104
  while date <= edate:
112
- func = eval('fix_{}_records'.format(table))
113
- cntall += func(date)
114
- date = PgUtil.adddate(date, 0, 0, 1)
115
-
105
+ (ndate, cond) = get_next_date(date, edate)
106
+ cntall += func(date, cond)
107
+ date = PgUtil.adddate(ndate, 0, 0, 1)
108
+
116
109
  if cntall > 2:
117
110
  PgLOG.pglog("{}: Total {} records updated".format(table, cntall), PgLOG.LOGWRN)
118
111
 
112
+ def get_next_date(date, edate):
113
+
114
+ if date < edate:
115
+ ndate = PgUtil.enddate(date, 'M')
116
+ if ndate > edate: ndate = edate
117
+ if date < ndate:
118
+ cond = f"BETWEEN '{date}' AND '{ndate}'"
119
+ else:
120
+ cond = f"= '{date}'"
121
+
122
+ return (ndate, cond)
123
+
119
124
 
120
- def fix_allusage_records(date):
125
+ def fix_allusage_records(date, cnd):
121
126
 
122
127
  cnt = 0
123
128
  ms = re.match(r'^(\d+)-', date)
124
129
  year = ms.group(1)
125
130
  table = 'allusage_' + year
126
- cond = "date = '{}' AND region IS NULL".format(date)
131
+ cond = f"date {cnd} AND region IS NULL"
127
132
  pgrecs = PgDBI.pgmget(table, 'aidx, email, ip', cond, PgLOG.LGEREX)
128
133
  if not pgrecs: return 0
129
134
  cnt = len(pgrecs['ip']) if pgrecs else 0
@@ -134,15 +139,15 @@ def fix_allusage_records(date):
134
139
  mcnt += PgDBI.pgupdt(table, record, "aidx = '{}'".format(pgrecs['aidx'][i]))
135
140
 
136
141
  s = 's' if cnt > 1 else ''
137
- PgLOG.pglog("{}: {} of {} record{} updated for {}".format(table, mcnt, cnt, s, date), PgLOG.LOGWRN)
142
+ PgLOG.pglog(f"{table}: {mcnt} of {cnt} record{s} updated for date {cnd}", PgLOG.LOGWRN)
138
143
 
139
144
  return mcnt
140
145
 
141
- def fix_tdsusage_records(date):
146
+ def fix_tdsusage_records(date, cnd):
142
147
 
143
148
  table = 'tdsusage'
144
- cond = "date = '{}' AND region IS NULL".format(date)
145
- pgrecs = PgDBI.pgmget(table, 'time, email, ip', cond, PgLOG.LGEREX)
149
+ cond = f"date {cnd} AND region IS NULL"
150
+ pgrecs = PgDBI.pgmget(table, 'date, time, email, ip', cond, PgLOG.LGEREX)
146
151
  if not pgrecs: return 0
147
152
  cnt = len(pgrecs['ip']) if pgrecs else 0
148
153
  mcnt = 0
@@ -150,18 +155,18 @@ def fix_tdsusage_records(date):
150
155
  ip = pgrecs['ip'][i]
151
156
  record = PgIPInfo.get_missing_ipinfo(ip, pgrecs['email'][i])
152
157
  if record:
153
- cond = "date = '{}' AND time = '{}' AND ip = '{}'".format(date, pgrecs['time'][i], ip)
158
+ cond = "date = '{}' AND time = '{}' AND ip = '{}'".format(pgrecs['date'][i], pgrecs['time'][i], ip)
154
159
  mcnt += PgDBI.pgupdt(table, record, cond)
155
160
 
156
161
  s = 's' if cnt > 1 else ''
157
- PgLOG.pglog("{}: {} of {} record{} updated for {}".format(table, mcnt, cnt, s, date), PgLOG.LOGWRN)
162
+ PgLOG.pglog(f"{table}: {mcnt} of {cnt} record{s} updated for date {cnd}", PgLOG.LOGWRN)
158
163
 
159
164
  return mcnt
160
165
 
161
- def fix_codusage_records(date):
166
+ def fix_codusage_records(date, cnd):
162
167
 
163
168
  table = 'codusage'
164
- cond = "date = '{}' AND region IS NULL".format(date)
169
+ cond = f"date {cnd} AND region IS NULL"
165
170
  pgrecs = PgDBI.pgmget(table, 'codidx, email, ip', cond, PgLOG.LGEREX)
166
171
  if not pgrecs: return 0
167
172
  cnt = len(pgrecs['ip']) if pgrecs else 0
@@ -172,14 +177,14 @@ def fix_codusage_records(date):
172
177
  mcnt += PgDBI.pgupdt(table, record, "codidx = '{}'".format(pgrecs['codidx'][i]))
173
178
 
174
179
  s = 's' if cnt > 1 else ''
175
- PgLOG.pglog("{}: {} of {} record{} updated for {}".format(table, mcnt, cnt, s, date), PgLOG.LOGWRN)
180
+ PgLOG.pglog(f"{table}: {mcnt} of {cnt} record{s} updated for date {cnd}", PgLOG.LOGWRN)
176
181
 
177
182
  return mcnt
178
183
 
179
- def fix_wuser_records(date):
184
+ def fix_wuser_records(date, cnd):
180
185
 
181
186
  table = 'wuser'
182
- cond = "start_date = '{}' AND region IS NULL".format(date)
187
+ cond = f"start_date {cnd} AND region IS NULL"
183
188
  pgrecs = PgDBI.pgmget(table, 'wuid, email, ip', cond, PgLOG.LGEREX)
184
189
  if not pgrecs: return 0
185
190
  cnt = len(pgrecs['ip']) if pgrecs else 0
@@ -192,14 +197,14 @@ def fix_wuser_records(date):
192
197
  mcnt += PgDBI.pgupdt(table, record, "wuid = '{}'".format(pgrecs['wuid'][i]))
193
198
 
194
199
  s = 's' if cnt > 1 else ''
195
- PgLOG.pglog("{}: {} of {} record{} updated for {}".format(table, mcnt, cnt, s, date), PgLOG.LOGWRN)
200
+ PgLOG.pglog(f"{table}: {mcnt} of {cnt} record{s} updated for start_date {cnd}", PgLOG.LOGWRN)
196
201
 
197
202
  return mcnt
198
203
 
199
- def fix_ipinfo_records(date):
204
+ def fix_ipinfo_records(date, cnd):
200
205
 
201
206
  table = 'ipinfo'
202
- cond = "adddate = '{}' AND region IS NULL".format(date)
207
+ cond = f"adddate {cnd} AND region IS NULL"
203
208
  pgrecs = PgDBI.pgmget(table, 'ip', cond, PgLOG.LGEREX)
204
209
  if not pgrecs: return 0
205
210
  cnt = len(pgrecs['ip']) if pgrecs else 0
@@ -208,7 +213,7 @@ def fix_ipinfo_records(date):
208
213
  if PgIPInfo.set_ipinfo(pgrecs['ip'][i]): mcnt +=1
209
214
 
210
215
  s = 's' if cnt > 1 else ''
211
- PgLOG.pglog("{}: {} of {} record{} updated for {}".format(table, mcnt, cnt, s, date), PgLOG.LOGWRN)
216
+ PgLOG.pglog(f"{table}: {mcnt} of {cnt} record{s} updated for adddate {cnd}", PgLOG.LOGWRN)
212
217
 
213
218
  return mcnt
214
219
 
@@ -3,7 +3,7 @@
3
3
 
4
4
  Usage: fillipinfo [-b] -t TableName [-N NumberDay] [-m YearMonths] [-y Years]
5
5
 
6
- select option, -t and -m, -N or -y to run this application.
6
+ select option, -t and -d, -m, -N or -y to run this application.
7
7
 
8
8
  - Option -b, log process information into logfile only;
9
9
 
@@ -13,6 +13,8 @@
13
13
 
14
14
  - Option -N, fix usage info in recent NumberDay days;
15
15
 
16
+ - Option -d, fix usage info in given dates;
17
+
16
18
  - Option -m, fix usage info in given months;
17
19
 
18
20
  - Option -y, fix usage info in given years.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rda_python_metrics
3
- Version: 1.0.22
3
+ Version: 1.0.23
4
4
  Summary: RDA Python Package to gather and view data usage metrics
5
5
  Author-email: Zaihua Ji <zji@ucar.edu>
6
6
  Project-URL: Homepage, https://github.com/NCAR/rda-python-metrics
@@ -11,8 +11,8 @@ rda_python_metrics/fillcountry.py,sha256=7i5LNi3scRoyRCT6t7aeNTGKOpxzJ2mA9tnvUqj
11
11
  rda_python_metrics/fillendtime.py,sha256=skZttlpoY19g0dGwqGQI8t_1YPPTPEXwg3EfNlfL90I,2533
12
12
  rda_python_metrics/fillglobususage.py,sha256=ahz8XnnJdD_AbSYqJ34lWmDuzws_-SNmCR8QE20aovA,8539
13
13
  rda_python_metrics/fillglobususage.usg,sha256=1GgmCP22IQZdADwL5Mmkz3v8Ws-G7U3teQ1AxRJfV_4,637
14
- rda_python_metrics/fillipinfo.py,sha256=O2uTGCw13ITZn6tfhNT_9DQJ8-RM5TVZfYIJCYm01oY,6726
15
- rda_python_metrics/fillipinfo.usg,sha256=6NoOTStxsVXwycN8u8znnwC6AemKftR2ZGrW_RL41og,647
14
+ rda_python_metrics/fillipinfo.py,sha256=w3IEyxFo8oVGWw8ILAr_GHZ4d8BOf1wWcChIp6OQAtk,6745
15
+ rda_python_metrics/fillipinfo.usg,sha256=YeCR58xGv0emqHUZ_9R977HrqaeBwbd6j5QRF2Lc7TA,702
16
16
  rda_python_metrics/filloneorder.py,sha256=ADHbcKCDh9bJunnxYbkbjwU2QpC43hvGlLWaURHNxkg,5433
17
17
  rda_python_metrics/filloneorder.usg,sha256=mtOySKx6-D4k2bbTcmi6cSYtINiycRyHQkHozi0CQu0,1466
18
18
  rda_python_metrics/fillosdfusage.py,sha256=z62l7RtbcfnR84xn2ffQXq0cPfcBkvUciP3u6vb09JI,7855
@@ -44,9 +44,9 @@ rda_python_metrics/viewwebfile.py,sha256=HSMNkQQawonu6W3blV7g9UbJuNy9VAOn9COqgmj
44
44
  rda_python_metrics/viewwebfile.usg,sha256=lTNi8Yu8BUJuExEDJX-vsJyWUSUIQTS-DiiBEVFo33s,10054
45
45
  rda_python_metrics/viewwebusage.py,sha256=ES2lI8NaCeCpTGi94HU-cDRBxHMiUBbplyYsZf2KqF0,16650
46
46
  rda_python_metrics/viewwebusage.usg,sha256=OVDZ78p87E3HLW34ZhasNJ7Zmw8XXjmZPPWZfRhPLXo,9936
47
- rda_python_metrics-1.0.22.dist-info/licenses/LICENSE,sha256=1dck4EAQwv8QweDWCXDx-4Or0S8YwiCstaso_H57Pno,1097
48
- rda_python_metrics-1.0.22.dist-info/METADATA,sha256=1EgQwJ6ezL7DX5PRIPAP6tdEfG_3aIKdDstqjQ7NJN0,761
49
- rda_python_metrics-1.0.22.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
50
- rda_python_metrics-1.0.22.dist-info/entry_points.txt,sha256=YfFLzlE3rdufSV471VsDnfYptnt1lR08aSrxPXlKqlY,1185
51
- rda_python_metrics-1.0.22.dist-info/top_level.txt,sha256=aoBgbR_o70TP0QmMW0U6inRHYtfKld47OBmnWnLnDOs,19
52
- rda_python_metrics-1.0.22.dist-info/RECORD,,
47
+ rda_python_metrics-1.0.23.dist-info/licenses/LICENSE,sha256=1dck4EAQwv8QweDWCXDx-4Or0S8YwiCstaso_H57Pno,1097
48
+ rda_python_metrics-1.0.23.dist-info/METADATA,sha256=FIeMLBkhmlMKHNmm7Uq74ipwiT6L-u4lTL5lVGl8AjI,761
49
+ rda_python_metrics-1.0.23.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
50
+ rda_python_metrics-1.0.23.dist-info/entry_points.txt,sha256=YfFLzlE3rdufSV471VsDnfYptnt1lR08aSrxPXlKqlY,1185
51
+ rda_python_metrics-1.0.23.dist-info/top_level.txt,sha256=aoBgbR_o70TP0QmMW0U6inRHYtfKld47OBmnWnLnDOs,19
52
+ rda_python_metrics-1.0.23.dist-info/RECORD,,