saq1b commited on
Commit
f572332
·
verified ·
1 Parent(s): 7b56813

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +12 -8
  2. app.py +63 -0
  3. requirements.txt +3 -0
Dockerfile CHANGED
@@ -1,13 +1,17 @@
1
- FROM nginx:alpine
2
 
3
- # Copy all files to the NGINX html directory
4
- COPY . /usr/share/nginx/html/
5
 
6
- # Set proper permissions
7
- RUN chmod -R 755 /usr/share/nginx/html
8
 
9
- # Expose port 7860
 
 
 
 
 
10
  EXPOSE 7860
11
 
12
- # Start NGINX
13
- CMD ["nginx", "-g", "daemon off;"]
 
1
+ FROM python:3.9-slim
2
 
3
+ WORKDIR /app
 
4
 
5
+ COPY requirements.txt .
6
+ RUN pip install --no-cache-dir -r requirements.txt
7
 
8
+ COPY . .
9
+
10
+ # Create directories if they don't exist
11
+ RUN mkdir -p templates static
12
+
13
+ # Expose the port that Flask will run on
14
  EXPOSE 7860
15
 
16
+ # Command to run the Flask app
17
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, jsonify
2
+ import requests
3
+ import json
4
+
5
+ app = Flask(__name__)
6
+
7
+ API_URL = "https://badimo.nyc3.digitaloceanspaces.com/trade/frequency/snapshot/month/latest.json"
8
+
9
+ @app.route('/')
10
+ def index():
11
+ return render_template('index.html')
12
+
13
+ @app.route('/api/data')
14
+ def get_data():
15
+ try:
16
+ response = requests.get(API_URL)
17
+ response.raise_for_status()
18
+ data = response.json()
19
+
20
+ # Add additional derived metrics
21
+ for item in data:
22
+ item['RarityScore'] = round(item['TimesTraded'] / item['UniqueCirculation'] if item['UniqueCirculation'] > 0 else 0, 2)
23
+
24
+ return jsonify(data)
25
+ except Exception as e:
26
+ return jsonify({"error": str(e)}), 500
27
+
28
+ @app.route('/api/stats')
29
+ def get_stats():
30
+ try:
31
+ response = requests.get(API_URL)
32
+ response.raise_for_status()
33
+ data = response.json()
34
+
35
+ # Generate stats by type
36
+ stats_by_type = {}
37
+ for item in data:
38
+ item_type = item['Type']
39
+ if item_type not in stats_by_type:
40
+ stats_by_type[item_type] = {
41
+ 'count': 0,
42
+ 'totalTraded': 0,
43
+ 'totalCirculation': 0,
44
+ 'averageDemand': 0
45
+ }
46
+
47
+ stats_by_type[item_type]['count'] += 1
48
+ stats_by_type[item_type]['totalTraded'] += item['TimesTraded']
49
+ stats_by_type[item_type]['totalCirculation'] += item['UniqueCirculation']
50
+
51
+ # Calculate averages
52
+ for type_key in stats_by_type:
53
+ if stats_by_type[type_key]['totalCirculation'] > 0:
54
+ stats_by_type[type_key]['averageDemand'] = round(
55
+ stats_by_type[type_key]['totalTraded'] / stats_by_type[type_key]['totalCirculation'], 2
56
+ )
57
+
58
+ return jsonify(stats_by_type)
59
+ except Exception as e:
60
+ return jsonify({"error": str(e)}), 500
61
+
62
+ if __name__ == '__main__':
63
+ app.run(host='0.0.0.0', port=7860, debug=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ flask==2.2.3
2
+ requests==2.28.2
3
+ gunicorn==20.1.0