2023-04-05 16:28:39 -05:00
|
|
|
from flask import Flask
|
|
|
|
from flask_restful import Resource, Api, reqparse
|
|
|
|
import pandas as pd
|
2023-04-05 18:27:14 -05:00
|
|
|
import numpy as np
|
2023-04-05 16:28:39 -05:00
|
|
|
import ast
|
2023-04-05 17:36:16 -05:00
|
|
|
import kiss
|
2023-04-05 18:21:37 -05:00
|
|
|
import glob
|
2023-04-05 16:28:39 -05:00
|
|
|
app = Flask(__name__)
|
2023-04-05 16:58:35 -05:00
|
|
|
api = Api(app)
|
|
|
|
|
|
|
|
class Users(Resource):
|
|
|
|
def get(self):
|
|
|
|
data = pd.read_csv('users.csv') # read CSV
|
|
|
|
data = data.to_dict() # convert dataframe to dictionary
|
|
|
|
return {'data': data}, 200 # return data and 200 OK code
|
2023-04-05 17:36:16 -05:00
|
|
|
|
2023-04-05 16:58:35 -05:00
|
|
|
class Locations(Resource):
|
|
|
|
def get(self):
|
|
|
|
data = pd.read_csv('locations.csv') # read CSV
|
|
|
|
data = data.to_dict() # convert dataframe to dictionary
|
|
|
|
return {'data': data}, 200 # return data and 200 OK code
|
2023-04-05 17:36:16 -05:00
|
|
|
|
2023-04-05 18:21:37 -05:00
|
|
|
# Read some log files
|
|
|
|
list_stacked = pd.DataFrame()
|
|
|
|
file_list = glob.glob("logs/*.log")
|
2023-04-05 18:27:14 -05:00
|
|
|
#print(file_list)
|
2023-04-05 18:21:37 -05:00
|
|
|
for file in file_list:
|
|
|
|
file1 = pd.read_csv(file)
|
|
|
|
list_stacked = pd.concat([list_stacked, file1])
|
2023-04-05 18:27:14 -05:00
|
|
|
# TODO Can we do this without numpy?
|
|
|
|
list_stacked.replace(np.nan, 0, inplace=True)
|
2023-04-05 18:21:37 -05:00
|
|
|
|
|
|
|
# TODO do I need to rearrange the data to a different format? I want all the
|
|
|
|
# data for one packet (one row) together.
|
|
|
|
|
|
|
|
class Packets(Resource):
|
|
|
|
def get(self):
|
|
|
|
data = list_stacked
|
|
|
|
data = data.to_dict() # convert dataframe to dictionary
|
|
|
|
return {'data': data}, 200 # return data and 200 OK code
|
|
|
|
|
2023-04-05 16:58:35 -05:00
|
|
|
api.add_resource(Users, '/users') # '/users' is our entry point for Users
|
|
|
|
api.add_resource(Locations, '/locations') # and '/locations' is our entry point for Locations
|
2023-04-05 18:21:37 -05:00
|
|
|
api.add_resource(Packets, '/packets') # and '/locations' is our entry point for Locations
|
2023-04-05 16:58:35 -05:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2023-04-05 17:36:16 -05:00
|
|
|
app.run(debug=True) # run our Flask app
|