import numpy as np import matplotlib.pyplot as plt import pandas as pd from timeseries import read_data # Load input data index = 2 data = read_data('data_2D.txt', index) # Plot data with year-level granularity start = '2003' end = '2011' plt.figure() data[start:end].plot() plt.title('Input data from ' + start + ' to ' + end) # Plot data with month-level granularity start = '1998-2' end = '2006-7' plt.figure() data[start:end].plot() plt.title('Input data from ' + start + ' to ' + end) plt.show()
#!/usr/bin/python from flask import Flask, jsonify, request, abort from timeseries import read_data import json app = Flask(__name__) data, equipments, sensors_per_equipment = read_data('dataset/data-large.csv') @app.route('/timeseries') def series(): device_id = request.args.get('deviceid') sensor = request.args.get('sensor') for d in data: if d.equipment == device_id and d.sensor == sensor: return d.serialize abort(404) @app.route('/sensors') def sensors(): device_id = request.args.get('deviceid') if (device_id in sensors_per_equipment): return json.dumps(sensors_per_equipment[device_id]) abort(404) @app.route('/devices') def devices():
import numpy as np import pandas as pd import matplotlib.pyplot as plt from timeseries import read_data # Input filename input_file = 'data_2D.txt' # Load data x1 = read_data(input_file, 2) x2 = read_data(input_file, 3) # Create pandas dataframe for slicing data = pd.DataFrame({'dim1': x1, 'dim2': x2}) # Plot data start = '1968' end = '1975' data[start:end].plot() plt.title('Data overlapped on top of each other') # Filtering using conditions # - 'dim1' is smaller than a certain threshold # - 'dim2' is greater than a certain threshold data[(data['dim1'] < 45) & (data['dim2'] > 30)].plot() plt.title('dim1 < 45 and dim2 > 30') # Adding two dataframes plt.figure() diff = data[start:end]['dim1'] + data[start:end]['dim2']