Compare commits
No commits in common. "e6dc6b06cbb9a99bf8451ba0a3419b84a6227f3b" and "225dc70cc8b0289a92a83a85865449f803e2e98a" have entirely different histories.
e6dc6b06cb
...
225dc70cc8
4 changed files with 40 additions and 70 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,4 +3,3 @@ legacy/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.pyc
|
*.pyc
|
||||||
*.pyo
|
*.pyo
|
||||||
*.png
|
|
||||||
|
|
2
numberdealers/users.py
Executable file → Normal file
2
numberdealers/users.py
Executable file → Normal file
|
@ -1,5 +1,3 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
from os.path import expanduser
|
from os.path import expanduser
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from datetime import timezone, datetime
|
from datetime import timezone, datetime
|
||||||
from numberdealers import parse_numberdealers
|
import parse_numberdealers
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
@ -10,8 +10,8 @@ def xy(messages):
|
||||||
x = []
|
x = []
|
||||||
y = []
|
y = []
|
||||||
for msg in messages:
|
for msg in messages:
|
||||||
# x.append(datetime.fromtimestamp(msg.create_at / 1000, timezone.utc))
|
x.append(datetime.fromtimestamp(msg.create_at / 1000, timezone.utc))
|
||||||
x.append(msg.create_at / 1000)
|
# x.append(msg.create_at / 1000)
|
||||||
y.append(msg.recognized_number)
|
y.append(msg.recognized_number)
|
||||||
return x, y
|
return x, y
|
||||||
|
|
||||||
|
@ -22,71 +22,44 @@ def find(xs, condition):
|
||||||
return i
|
return i
|
||||||
|
|
||||||
|
|
||||||
def abline(slope, intercept, point1_x, point2_x):
|
def abline(slope, intercept):
|
||||||
"""Plot a line from slope and intercept"""
|
"""Plot a line from slope and intercept"""
|
||||||
axes = plt.gca()
|
axes = plt.gca()
|
||||||
x_vals = np.array([point1_x, point2_x])
|
x_vals = np.array(axes.get_xlim())
|
||||||
y_vals = slope * x_vals + intercept
|
y_vals = slope * x_vals + intercept
|
||||||
plt.plot(x_vals, y_vals, linewidth=1, color='grey')
|
plt.plot(x_vals, y_vals, '--')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
import sys
|
import sys
|
||||||
if len(sys.argv) <= 2:
|
|
||||||
print("Usage: plot_numberdealers.py <numberdealers.json> <numberdealers-ng.json>")
|
|
||||||
return 1
|
|
||||||
with open(sys.argv[1], encoding="utf-8") as fh:
|
with open(sys.argv[1], encoding="utf-8") as fh:
|
||||||
numbers_og, _errors = parse_numberdealers.parse(fh)
|
numbers_og, _errors = parse_numberdealers.parse(fh)
|
||||||
with open(sys.argv[2], encoding="utf-8") as fh:
|
with open(sys.argv[2], encoding="utf-8") as fh:
|
||||||
numbers_ng, _errors = parse_numberdealers.parse(fh)
|
numbers_ng, _errors = parse_numberdealers.parse(fh)
|
||||||
|
|
||||||
start_of_current_slope = find(numbers_og, lambda msg: msg.create_at >= numbers_ng[0].create_at)
|
# start_of_current_slope = find(numbers_og, lambda msg: msg.recognized_number <= 10464)
|
||||||
# a = (y2-y1) / (x2-x1)
|
# slope_og = (
|
||||||
slope_og = (
|
# numbers_og[-1].recognized_number - numbers_og[start_of_current_slope].recognized_number
|
||||||
numbers_og[-1].recognized_number - numbers_og[start_of_current_slope].recognized_number
|
# ) / (
|
||||||
) / (
|
# numbers_og[-1].create_at/1000 - numbers_og[start_of_current_slope].create_at/1000
|
||||||
numbers_og[-1].create_at/1000 - numbers_og[start_of_current_slope].create_at/1000
|
# )
|
||||||
)
|
# # b = y - a x
|
||||||
# b = y - a x
|
# intercept_og = numbers_og[-1].recognized_number - slope_og * numbers_og[-1].create_at
|
||||||
intercept_og = numbers_og[-1].recognized_number - slope_og * numbers_og[-1].create_at/1000
|
|
||||||
|
|
||||||
slope_ng = (
|
# slope_ng = (
|
||||||
numbers_ng[-1].recognized_number - numbers_ng[0].recognized_number
|
# numbers_ng[-1].recognized_number - numbers_ng[0].recognized_number
|
||||||
) / (
|
# ) / (
|
||||||
numbers_ng[-1].create_at/1000 - numbers_ng[0].create_at/1000
|
# numbers_ng[-1].create_at/1000 - numbers_ng[0].create_at/1000
|
||||||
)
|
# )
|
||||||
intercept_ng = numbers_ng[-1].recognized_number - slope_ng * numbers_ng[-1].create_at/1000
|
# intercept_ng = numbers_ng[-1].recognized_number - slope_ng * numbers_ng[-1].create_at
|
||||||
|
|
||||||
# a1 x + b1 = a2 x + b2
|
fig, ax = plt.subplots()
|
||||||
# (a1 - a2) x = b2 - b1
|
|
||||||
# x = (b2 - b1) / (a1 - a2)
|
|
||||||
intercept_x = (intercept_ng - intercept_og) / (slope_og - slope_ng)
|
|
||||||
intercept_y = slope_ng * intercept_x + intercept_ng
|
|
||||||
|
|
||||||
fig, ax = plt.subplots(figsize=(15, 6))
|
|
||||||
ax.plot(*xy(numbers_og))
|
ax.plot(*xy(numbers_og))
|
||||||
ax.plot(*xy(numbers_ng))
|
ax.plot(*xy(numbers_ng))
|
||||||
abline(slope_og, intercept_og, numbers_og[-1].create_at/1000, intercept_x)
|
# abline(slope_og, -120000)
|
||||||
abline(slope_ng, intercept_ng, numbers_ng[-1].create_at/1000, intercept_x)
|
# abline(slope_ng, -500000)
|
||||||
|
plt.show()
|
||||||
plt.margins(x=0)
|
|
||||||
|
|
||||||
locs = np.append(
|
|
||||||
np.linspace(numbers_og[0].create_at/1000, numbers_ng[0].create_at/1000, 6),
|
|
||||||
[numbers_ng[-1].create_at/1000, intercept_x]
|
|
||||||
)
|
|
||||||
# func = lambda x: x < intercept_x
|
|
||||||
# locs = np.append(locs[func(locs)][:-1], [intercept_x])
|
|
||||||
labels = ["{:%Y-%m-%d}".format(datetime.fromtimestamp(x, timezone.utc)) for x in locs]
|
|
||||||
plt.xticks(locs, labels)
|
|
||||||
|
|
||||||
plt.grid()
|
|
||||||
|
|
||||||
# plt.show()
|
|
||||||
plt.savefig("plot.png")
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import sys
|
main()
|
||||||
sys.exit(main())
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ from numberdealers import parse_numberdealers, times, report_errors, numbers_per
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
channel = sys.argv[1]
|
|
||||||
numbers, errors = parse_numberdealers.parse(sys.stdin)
|
numbers, errors = parse_numberdealers.parse(sys.stdin)
|
||||||
|
|
||||||
if numbers == [] and errors == []:
|
if numbers == [] and errors == []:
|
||||||
|
@ -15,20 +14,21 @@ def main():
|
||||||
print("No valid number messages!")
|
print("No valid number messages!")
|
||||||
return
|
return
|
||||||
|
|
||||||
print(f"##### Checked ~{channel} from {numbers[0].recognized_number} up to {numbers[-1].recognized_number}")
|
print(f"Checked from {numbers[0].recognized_number} up to {numbers[-1].recognized_number}")
|
||||||
if "--no-errors" not in sys.argv[2:]:
|
print()
|
||||||
print()
|
report_errors.report_errors(errors)
|
||||||
report_errors.report_errors(errors)
|
print()
|
||||||
if "--no-times" not in sys.argv[2:]:
|
print("---")
|
||||||
print()
|
print()
|
||||||
print("```")
|
print("```")
|
||||||
times.report_times(numbers)
|
times.report_times(numbers)
|
||||||
print("```")
|
print("```")
|
||||||
if "--no-users" not in sys.argv[2:]:
|
print()
|
||||||
print()
|
print("---")
|
||||||
print("```")
|
print()
|
||||||
numbers_per_user.report_users(numbers)
|
print("```")
|
||||||
print("```")
|
numbers_per_user.report_users(numbers)
|
||||||
|
print("```")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in a new issue