#!/usr/bin/env python3 from datetime import timezone, datetime import parse_numberdealers import matplotlib.pyplot as plt import numpy as np def xy(messages): x = [] y = [] for msg in messages: x.append(datetime.fromtimestamp(msg.create_at / 1000, timezone.utc)) # x.append(msg.create_at / 1000) y.append(msg.recognized_number) return x, y def find(xs, condition): for i, x in enumerate(xs): if condition(x): return i def abline(slope, intercept): """Plot a line from slope and intercept""" axes = plt.gca() x_vals = np.array(axes.get_xlim()) y_vals = slope * x_vals + intercept plt.plot(x_vals, y_vals, '--') def main(): import sys with open(sys.argv[1], encoding="utf-8") as fh: numbers_og, _errors = parse_numberdealers.parse(fh) with open(sys.argv[2], encoding="utf-8") as fh: numbers_ng, _errors = parse_numberdealers.parse(fh) # start_of_current_slope = find(numbers_og, lambda msg: msg.recognized_number <= 10464) # slope_og = ( # 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 # ) # # b = y - a x # intercept_og = numbers_og[-1].recognized_number - slope_og * numbers_og[-1].create_at # slope_ng = ( # numbers_ng[-1].recognized_number - numbers_ng[0].recognized_number # ) / ( # 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 fig, ax = plt.subplots() ax.plot(*xy(numbers_og)) ax.plot(*xy(numbers_ng)) # abline(slope_og, -120000) # abline(slope_ng, -500000) plt.show() if __name__ == "__main__": main()