donate-cpu-server: Refactor diff handling. Statistics for a package is generated when the package is uploaded.
This commit is contained in:
parent
423e23b430
commit
c9db395d43
|
@ -2,6 +2,7 @@
|
||||||
# Server for 'donate-cpu.py'
|
# Server for 'donate-cpu.py'
|
||||||
|
|
||||||
import glob
|
import glob
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import re
|
import re
|
||||||
|
@ -242,36 +243,22 @@ def diffReport(resultsPath):
|
||||||
outToday = {}
|
outToday = {}
|
||||||
today = strDateTime()[:10]
|
today = strDateTime()[:10]
|
||||||
|
|
||||||
for filename in sorted(glob.glob(resultsPath + '/*')):
|
for filename in sorted(glob.glob(resultsPath + '/*.diff')):
|
||||||
if not os.path.isfile(filename):
|
if not os.path.isfile(filename):
|
||||||
continue
|
continue
|
||||||
uploadedToday = False
|
with open(filename, 'rt') as f:
|
||||||
firstLine = True
|
data = json.loads(f.read())
|
||||||
for line in open(filename, 'rt'):
|
uploadedToday = data['date'] == today
|
||||||
if firstLine:
|
for messageId, sums in data['sums']:
|
||||||
if line.startswith(today):
|
|
||||||
uploadedToday = True
|
|
||||||
firstLine = False
|
|
||||||
continue
|
|
||||||
line = line.strip()
|
|
||||||
if not line.endswith(']'):
|
|
||||||
continue
|
|
||||||
index = None
|
|
||||||
if line.startswith(OLD_VERSION + ' '):
|
|
||||||
index = 0
|
|
||||||
elif line.startswith('head '):
|
|
||||||
index = 1
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
messageId = line[line.rfind('[')+1:len(line)-1]
|
|
||||||
|
|
||||||
if messageId not in out:
|
if messageId not in out:
|
||||||
out[messageId] = [0, 0]
|
out[messageId] = [0, 0]
|
||||||
out[messageId][index] += 1
|
out[messageId][0] += sums[OLD_VERSION]
|
||||||
|
out[messageId][1] += sums['head']
|
||||||
if uploadedToday:
|
if uploadedToday:
|
||||||
if messageId not in outToday:
|
if messageId not in outToday:
|
||||||
outToday[messageId] = [0, 0]
|
outToday[messageId] = [0, 0]
|
||||||
outToday[messageId][index] += 1
|
outToday[messageId][0] += sums[OLD_VERSION]
|
||||||
|
outToday[messageId][1] += sums['head']
|
||||||
|
|
||||||
html = '<html><head><title>Diff report</title></head><body>\n'
|
html = '<html><head><title>Diff report</title></head><body>\n'
|
||||||
html += '<h1>Diff report</h1>\n'
|
html += '<h1>Diff report</h1>\n'
|
||||||
|
@ -283,6 +270,46 @@ def diffReport(resultsPath):
|
||||||
return html
|
return html
|
||||||
|
|
||||||
|
|
||||||
|
def generate_package_diff_statistics(filename):
|
||||||
|
is_diff = False
|
||||||
|
|
||||||
|
sums = {}
|
||||||
|
|
||||||
|
for line in open(filename, 'rt'):
|
||||||
|
line = line.strip()
|
||||||
|
if line == 'diff:':
|
||||||
|
is_diff = True
|
||||||
|
continue
|
||||||
|
elif not is_diff:
|
||||||
|
continue
|
||||||
|
if not line.endswith(']'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
version = None
|
||||||
|
if line.startswith(OLD_VERSION + ' '):
|
||||||
|
version = OLD_VERSION
|
||||||
|
elif line.startswith('head '):
|
||||||
|
version = 'head'
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
|
messageId = line[line.rfind('[')+1:len(line)-1]
|
||||||
|
|
||||||
|
if messageId not in sums:
|
||||||
|
sums[messageId] = { OLD_VERSION: 0, 'head': 0 }
|
||||||
|
|
||||||
|
sums[messageId][version] += 1
|
||||||
|
|
||||||
|
output = { 'date': strDateTime()[:10], 'sums': sums }
|
||||||
|
|
||||||
|
filename_diff = filename + '.diff'
|
||||||
|
if sums:
|
||||||
|
with open(filename_diff, 'wt') as f:
|
||||||
|
f.write(json.dumps(output))
|
||||||
|
elif os.path.isfile(filename_diff):
|
||||||
|
os.remove(filename_diff)
|
||||||
|
|
||||||
|
|
||||||
def diffMessageIdReport(resultPath, messageId):
|
def diffMessageIdReport(resultPath, messageId):
|
||||||
text = messageId + '\n'
|
text = messageId + '\n'
|
||||||
e = '[' + messageId + ']\n'
|
e = '[' + messageId + ']\n'
|
||||||
|
@ -823,7 +850,7 @@ def server(server_address_port, packages, packageIndex, resultPath):
|
||||||
if old_version_wrong:
|
if old_version_wrong:
|
||||||
continue
|
continue
|
||||||
print('results added for package ' + res.group(1))
|
print('results added for package ' + res.group(1))
|
||||||
filename = resultPath + '/' + res.group(1)
|
filename = os.path.join(resultPath, res.group(1))
|
||||||
with open(filename, 'wt') as f:
|
with open(filename, 'wt') as f:
|
||||||
f.write(strDateTime() + '\n' + data)
|
f.write(strDateTime() + '\n' + data)
|
||||||
# track latest added results..
|
# track latest added results..
|
||||||
|
@ -832,6 +859,8 @@ def server(server_address_port, packages, packageIndex, resultPath):
|
||||||
latestResults.append(filename)
|
latestResults.append(filename)
|
||||||
with open('latest.txt', 'wt') as f:
|
with open('latest.txt', 'wt') as f:
|
||||||
f.write(' '.join(latestResults))
|
f.write(' '.join(latestResults))
|
||||||
|
# generate package.diff..
|
||||||
|
generate_package_diff_statistics(filename)
|
||||||
elif cmd.startswith('write_info\nftp://'):
|
elif cmd.startswith('write_info\nftp://'):
|
||||||
# read data
|
# read data
|
||||||
data = cmd[11:]
|
data = cmd[11:]
|
||||||
|
|
Loading…
Reference in New Issue