diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6f3a291 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5501 +} \ No newline at end of file diff --git a/APIkeys.py b/APIkeys.py new file mode 100644 index 0000000..eb049f3 --- /dev/null +++ b/APIkeys.py @@ -0,0 +1 @@ +polygonAPIkey = 'acbdefghhijklmnopqrstuvwxyz' diff --git a/ScheduleManagerBD.sql b/ScheduleManagerBD.sql new file mode 100644 index 0000000..aa1ba7f --- /dev/null +++ b/ScheduleManagerBD.sql @@ -0,0 +1,64 @@ +DROP DATABASE IF EXISTS `MeetingScheduler` ; +CREATE DATABASE `MeetingScheduler` ; +USE `MeetingScheduler` ; + +SET NAMES utf8 ; +SET character_set_client = utf8mb4 ; + + +CREATE TABLE `rooms` ( +`room_num` int(4) NOT NULL, +`capacity` int(11) NOT NULL, +PRIMARY KEY (`room_num`) +) ENGINE=InnoDB; + +INSERT INTO `rooms` VALUES (100,30); + +CREATE TABLE `meetings` ( +`meeting_id` int(11) NOT NULL, +`time_id` int(11) NOT NULL, +`room_num` int(4) NOT NULL, +`desc` varchar(100) NULL, +PRIMARY KEY (`meeting_id`), +KEY `fk_room_num` (`room_num`), +CONSTRAINT `fk_room_numx` FOREIGN KEY (`room_num`) REFERENCES `rooms` (`room_num`) +) ENGINE=InnoDB; + +INSERT INTO `meetings` VALUES (1,1,100, 'This is a test'); + +CREATE TABLE `meeting_times` ( +`meeting_time_id` int(11) NOT NULL, +`meeting_id` int(11) NOT NULL, +`date_time_start` datetime NOT NULL, +`date_time_end` datetime NOT NULL, +PRIMARY KEY (`meeting_time_id`), +KEY `fk_meeting_idx` (`meeting_id`), +CONSTRAINT `fk_meeting_idx` FOREIGN KEY (`meeting_id`) REFERENCES `meetings` (`meeting_id`) +) ENGINE=InnoDB; + +INSERT INTO `meeting_times` VALUES (1,1,'2000-01-01 22:00:00', '2000-01-01 23:00:00'); + +CREATE TABLE `people` ( +`people_id` int(11) NOT NULL, +`name` varchar(50) NOT NULL, +`isManager` bool DEFAULT 0, +`meeting_id` int(11) DEFAULT NULL, +`password` varchar(50) NOT NULL, +PRIMARY KEY (`people_id`), +KEY `fk_meeting_idxs` (`meeting_id`), +CONSTRAINT `fk_meeting_idxs` FOREIGN KEY (`meeting_id`) REFERENCES `meetings` (`meeting_id`) +) ENGINE=InnoDB; + +INSERT INTO `people` VALUES (1,'default',1,1,'password'); + +CREATE TABLE `work_times` ( +`work_time_id` int(11) NOT NULL, +`people_id` int(11) NOT NULL, +`date_time_start` datetime NOT NULL, +`date_time_end` datetime NOT NULL, +PRIMARY KEY (`work_time_id`), +KEY `fk_people_idx` (`people_id`), +CONSTRAINT `fk_people_idx` FOREIGN KEY (`people_id`) REFERENCES `people` (`people_id`) +) ENGINE=InnoDB; + +INSERT INTO `work_times` VALUES (1,1,'2000-01-01 22:00:00', '2000-01-01 23:00:00'); diff --git a/__pycache__/APIkeys.cpython-39.pyc b/__pycache__/APIkeys.cpython-39.pyc new file mode 100644 index 0000000..15acac9 Binary files /dev/null and b/__pycache__/APIkeys.cpython-39.pyc differ diff --git a/__pycache__/app.cpython-312.pyc b/__pycache__/app.cpython-312.pyc new file mode 100644 index 0000000..e7d114a Binary files /dev/null and b/__pycache__/app.cpython-312.pyc differ diff --git a/__pycache__/app.cpython-39.pyc b/__pycache__/app.cpython-39.pyc index 36b7715..2b79179 100644 Binary files a/__pycache__/app.cpython-39.pyc and b/__pycache__/app.cpython-39.pyc differ diff --git a/app.py b/app.py index 9a0edec..c6c22bb 100644 --- a/app.py +++ b/app.py @@ -1,29 +1,99 @@ import re -from datetime import datetime - -from flask import Flask, render_template, request +from datetime import time +from flask_sqlalchemy import SQLAlchemy +from flask import Flask, render_template, request, redirect, url_for app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data.db' + +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) + +class employee(db.Model): + name = db.Column(db.String(100), nullable = False) + employee_id = db.Column(db.String(100), primary_key = True) + age = db.Column(db.Integer, nullable = False) + start_work = db.Column(db.types.Time()) + end_work = db.Column(db.types.Time()) + Password = db.Column(db.String(100),nullable = True) + # People = db.Column(db.PickleType, nullable = True) + +class meeting(db.Model): + Meeting_id = db.Column(db.Integer, primary_key = True) + Start = db.Column(db.types.Time(), nullable = False) + End = db.Column(db.types.Time(), nullable = False) + Room_number = db.Column(db.Integer, nullable = False) + People = db.Column(db.PickleType, nullable = False) +class room(db.Model): + Room_number = db.Column(db.Integer, primary_key = True) + meetings = db.Column(db.PickleType, nullable = True) -@app.route("/") +class groupdb(db.Model): + group_id = db.Column(db.Integer, primary_key = True) + group_db = db.Column(db.PickleType, nullable = False) + +class group(): + group_name = "" + employees = [] + def __init__ (self,group_name,employees): + self.group_name = group_name + self.employees = employees + +@app.before_request +def create_and_populate_db(): + db.create_all() + if employee.query.count == 0: + employees = [ + employee(name='Jim', id = '1', age=26, start_work = time(8,30,0,0), end_work= time(18,30,0,0), Password = 123), + employee(name='Jane', id = '2', age=53, start_work = time(7,30,0,0),end_work= time(18,30,0,0), Password = 456), + employee(name='John', id = '3', age=34, start_work = time(8,0,0,0), end_work= time(18,30,0,0),Password = 789) + ] + db.session.bulk_save_objects(employees) + db.session.commit() + +@app.route("/") def home(): return render_template('index.html') -@app.route("/hello//", ) -def hello_there(name,password): - now = datetime.now() - formatted_now = now.strftime("%A, %d %B, %Y at %X") - - # Filter the name argument to letters only using regular expressions. URL arguments - # can contain arbitrary text, so we restrict to safe characters only. - match_object = re.match("[a-zA-Z]+", name) +@app.route('/login', methods = ["GET","POST"]) +def hello_there(): + if request.method == "POST": + if (employee.query.count() == 0): + employees = [ + employee(name='Jim Davis', employee_id = '1', age=26, start_work = time(8,30,0,0), end_work= time(18,30,0,0), Password = 123), + employee(name='Jane Doe', employee_id = '2', age=53, start_work = time(7,30,0,0),end_work= time(18,30,0,0), Password = 456), + employee(name='John Dorne', employee_id = '3', age=34, start_work = time(8,0,0,0), end_work= time(18,30,0,0),Password = 789) + ] + db.session.bulk_save_objects(employees) + db.session.commit() + # group1 = group("group1", [employee.query.get(1),employee.query.get(2),employee.query.get(3)]) + if (meeting.query.count() == 0): + meetings = [ + meeting(Meeting_id = 1,Start = time(8,30,0,0) , End = time(11,30,0,0) ,Room_number = 1, People = group1), + meeting(Meeting_id = 2,Start = time(11,50,0,0) , End = time(12,30,0,0) ,Room_number = 2, People = group1) + ] + db.session.bulk_save_objects(meetings) + db.session.commit() + username = request.form.get("username") + password = request.form.get("password") + employee_num = employee.query.count() + print(employee.query.count()) + for i in range(employee.query.count()): + info = employee.query.get(i+1) + if (info.name == username) and (info.Password == password): + return render_template('input.html') - if match_object: - clean_name = match_object.group(0) - else: - clean_name = "Friend" +@app.route('/meeting_input', methods = ["GET","POST"]) +def main_menu(): + if request.method == "POST": + # Room_number = request.form.get("username") + # password = request.form.get("password") - content = "Hello there, " + clean_name + "! It's " + formatted_now + "your password is" + password - return content \ No newline at end of file + return render_template('input.html') +# todo; once the password is collected, we need to check +# it against all of the other passwords in the database + +if __name__ == '__main__': + app.run(debug=True) \ No newline at end of file diff --git a/instance/data.db b/instance/data.db new file mode 100644 index 0000000..38e1b44 Binary files /dev/null and b/instance/data.db differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d2a8358 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,10 @@ +#py -m pip install -r requirements.txt (do this to install all realavent python files) +pandas +polygon-api-client +numpy +sqlalchemy +flask +Flask-SQLAlchemy +requests +flask-marshmallow +marshmallow-sqlalchemy \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index fcbf6f0..c89770d 100644 --- a/templates/index.html +++ b/templates/index.html @@ -14,12 +14,12 @@

This is a Login Page

title = "goes to Google"> Click this link --> -
+
-
+

-
+

diff --git a/templates/input.html b/templates/input.html new file mode 100644 index 0000000..7e765e0 --- /dev/null +++ b/templates/input.html @@ -0,0 +1,81 @@ + + + + + + + Enter Meeting/People + + + + +
+ +

Enter Meeting

+ + +
+
+ + +
+
+ + +
+

Meeting Time:

+
+
+ + +
+
+ + +
+
+ +
+ + +

Add Person

+
+
+ + +
+ + +

Work Time:

+
+
+ + +
+
+ + +
+
+ +
+ + + \ No newline at end of file diff --git a/templates/page.html b/templates/page.html new file mode 100644 index 0000000..e0a0b22 --- /dev/null +++ b/templates/page.html @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/templates/style.css b/templates/style.css new file mode 100644 index 0000000..217eb34 --- /dev/null +++ b/templates/style.css @@ -0,0 +1,43 @@ +head{ + + +} + +body{ + background-image: url(https://wallpaper.dog/large/20395458.jpg); + background-repeat: no-repeat; + background-attachment: fixed; + background-position: center; + background-size: cover; + + + /*background: linear-gradient(skyblue, rgb(132, 83, 155)); + background-repeat: no-repeat; + background-attachment: fixed; + margin-top: 300px; + margin-left: auto; + margin-right: auto; + text-align: center;*/ +} + +h1{ + font-family: "impact"; +} + +p{ + font-family: "consolas"; + opacity: 1 +} + +#box{ + margin-top: 300px; + margin-left: auto; + margin-right: auto; + text-align: center; + border: 5px solid; + border-style: outset; + width: 500px; + height: 300px; + background-color: rgb(255, 255, 255,.3); + +} \ No newline at end of file diff --git a/test_app.py b/test_app.py new file mode 100644 index 0000000..ef0c77e --- /dev/null +++ b/test_app.py @@ -0,0 +1,173 @@ +from flask import Flask, render_template, request, jsonify +from flask_sqlalchemy import SQLAlchemy +from flask_marshmallow import Marshmallow +import sqlalchemy as sa +from sqlalchemy.orm import sessionmaker +from sqlalchemy import Table, Column, Integer, String, Float +from APIkeys import polygonAPIkey +from polygon import RESTClient +import pandas as pd +import numpy as np +import sqlite3 +import os + +basedir = os.path.abspath(os.path.dirname(__file__)) + +# Create flask app instance +vol_app = Flask(__name__) +vol_app.config["SQLALCHEMY_DATABASE_URI"] = 'sqlite:///' + os.path.join(basedir, 'vol_app.db') + +db = SQLAlchemy(vol_app) +ma = Marshmallow(vol_app) + +# Create client and authenticate w/ API key // rate limit 5 requests per min +client = RESTClient(polygonAPIkey) # api_key is used + +# Declare model +class VolData(db.Model): + __tablename__ = 'vol_table' + id = db.Column(db.Integer, primary_key=True) + ticker = db.Column(db.String, nullable=True, unique=True) + std_dev = db.Column(db.Float, nullable=True) + image_url = db.Column(db.String, nullable=True) + + def __init__(self, ticker, std_dev, image_url) -> None: + super(VolData, self).__init__() + self.ticker = ticker + self.std_dev = std_dev + self.image_url = image_url + + def __repr__(self) -> str: + return '' % self.ticker + +# Schema +class VolDataSchema(ma.Schema): + class Meta: + fields = ('id', 'ticker', 'std_dev', 'image_url') + +single_vol_data_schema = VolDataSchema() +multiple_vol_data_schema = VolDataSchema(many=True) + +# Create tables/db file +with vol_app.app_context(): + db.create_all() + + +# Main url +@vol_app.route('/', methods=['GET']) +def create_main(): + + all_data = VolData.query.all() + all_data_ser = multiple_vol_data_schema.dump(all_data) + all_data_df = pd.DataFrame(all_data_ser) + + print(all_data_df) + + return render_template('index.html', volatility_data=all_data_df) + + +# Add vol data entry to database +@vol_app.route('/data', methods=['POST']) +def add_vol_data(): + stock_tickers = request.json['tickers'] + + # Empty dataframe to store log returns + std_devs_data = pd.DataFrame() + + for i in stock_tickers: + print('processing ' + i) + + try: + # Request daily bars + data_request = client.get_aggs(ticker = i, + multiplier = 1, + timespan = 'day', + from_ = '2022-09-01', + to = '2023-03-25') + + # List of polygon agg objects to DataFrame + price_data = pd.DataFrame(data_request) + + # Create Date column + price_data['Date'] = price_data['timestamp'].apply( + lambda x: pd.to_datetime(x*1000000)) + + + price_data = price_data.set_index('Date') + + price_data['log_returns'] = np.log(price_data.close) - np.log( + price_data.close.shift(1)) + + # Rolling stdDev window + rolling_std_dev_window = 20 + + # Rolling stdDev log returns + price_data['std_devs'] = price_data['log_returns'].rolling( + center=False, window = rolling_std_dev_window).std() + + std_devs_data[i] = price_data.std_devs + + except Exception as e: + print(str(e) + 'error on ticker ' + i) + continue + + # Trim data + std_devs_data = std_devs_data[rolling_std_dev_window:] + + # Rename index before transpose + std_devs_data.index = std_devs_data.index.rename('idx') + + # Transpose data + sorted_data = std_devs_data[-1:].T + + # Reset index + sorted_data.reset_index(inplace=True) + + # Rename column + sorted_data = sorted_data.rename( + columns={sorted_data.columns[0]: "tickers", + sorted_data.columns[1]: "std_devs"}) + + # Sort data + sorted_data = sorted_data.sort_values(by=['std_devs'], + ascending=False, + ignore_index=True) + + # Add urls to dataframe + for j in sorted_data['tickers']: + iconUrl = client.get_ticker_details(ticker=j).branding.icon_url + iconUrl = iconUrl + '?apiKey=' + polygonAPIkey + sorted_data.loc[sorted_data['tickers'] == j, 'image_urls'] = iconUrl + + # print(sorted_data) + + entry_list = [] + + for k in sorted_data.itertuples(index=False): + new_entry = VolData(k.tickers, + k.std_devs, + k.image_urls) + entry_list.append(new_entry) + + with vol_app.app_context(): + Session = sessionmaker(bind=db.engine) + session = Session() + + for l in entry_list: + try: + session.add(l) + session.commit() + except: + print('Unable to add ' + l.ticker + ' to db.') + continue + # Commit the changes to the database + session.close() + + return sorted_data.to_dict('records') + + +@vol_app.route('/data', methods=['GET']) +def get_vol_data(): + all_data = VolData.query.all() + all_data_ser = multiple_vol_data_schema.dump(all_data) + return jsonify(all_data_ser) \ No newline at end of file diff --git a/vol_app.db b/vol_app.db new file mode 100644 index 0000000..9f088e1 Binary files /dev/null and b/vol_app.db differ