Skip to content

Commit f66651d

Browse files
Merge pull request #3 from eevanlai-stack/revert-2-cursor/process-recent-data-5725
Revert "Process recent data"
2 parents ad2b6b3 + e8d9c42 commit f66651d

File tree

2 files changed

+239
-7
lines changed

2 files changed

+239
-7
lines changed
Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
name: Python Package using Conda
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
-main
7+
-release/*
8+
on:
9+
pull_request:
10+
branches:
11+
- main
12+
on:
13+
schedule:
14+
- cron: "0 2 * * 1-5"
415

5-
jobs:
6-
build-linux:
7-
runs-on: ubuntu-latest
8-
strategy:
16+
on:
17+
workflow_dispatch:
18+
19+
jobs:
20+
my_job:
21+
name: deploy to staging
22+
runs-on: ubuntu-22.04
923
max-parallel: 5
1024

25+
- name: Setup Node
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: '20.x'
29+
1130
steps:
1231
- uses: actions/checkout@v4
1332
- name: Set up Python 3.10
@@ -19,7 +38,7 @@ jobs:
1938
# $CONDA is an environment variable pointing to the root of the miniconda directory
2039
echo $CONDA/bin >> $GITHUB_PATH
2140
- name: Install dependencies
22-
run: |
41+
run: npm install
2342
conda env update --file environment.yml --name base
2443
- name: Lint with flake8
2544
run: |
@@ -30,5 +49,26 @@ jobs:
3049
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
3150
- name: Test with pytest
3251
run: |
33-
conda install pytest
52+
conda install pjobs:
53+
test:
54+
name: Test on node ${{ matrix.node_version }} and ${{ matrix.os }}
55+
runs-on: ${{ matrix.os }}
56+
strategy:
57+
matrix:
58+
node_version: ['18.x', '20.x']
59+
os: [ubuntu-latest, windows-latest, macOS-latest]
60+
61+
steps:
62+
- uses: actions/checkout@v4
63+
- name: Use Node.js ${{ matrix.node_version }}
64+
uses: actions/setup-node@v4
65+
with:
66+
node-version: ${{ matrix.node_version }}
67+
68+
- name: npm install, build and test
69+
run: |
70+
npm install
71+
npm run build --if-present
72+
npm testytest
3473
pytest
74+

app.py

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,193 @@
66
CORS(app)
77

88

9+
# 1. GPS定位
10+
@app.route('/gps', methods=['GET'])
11+
def get_location():
12+
# 这里需要调用GPS定位的API,获取用户的经纬度信息
13+
# 由于GPS定位需要在移动设备上才能实现,这里我们只返回一个模拟数据
14+
location = {'latitude': 31.2304, 'longitude': 121.4737}
15+
return jsonify(location)
16+
17+
18+
# 2. EPF (Employee Provident Fund) 公积金计算
19+
@app.route('/epf', methods=['POST'])
20+
def calculate_epf():
21+
data = request.get_json(silent=True) or {}
22+
if 'salary' not in data:
23+
raise BadRequest('Missing field: salary')
24+
try:
25+
salary = float(data.get('salary'))
26+
except (TypeError, ValueError):
27+
raise BadRequest('Invalid salary')
28+
29+
# EPF的计算逻辑,这里假设员工和雇主各缴纳11%和13%
30+
employee_contribution = round(salary * 0.11, 2)
31+
employer_contribution = round(salary * 0.13, 2)
32+
total_contribution = round(employee_contribution + employer_contribution, 2)
33+
return jsonify({
34+
'employee_contribution': employee_contribution,
35+
'employer_contribution': employer_contribution,
36+
'total_contribution': total_contribution
37+
})
38+
39+
40+
# 3. PERKESO (Social Security Organization) 社险计算
41+
@app.route('/perkeso', methods=['POST'])
42+
def calculate_perkeso():
43+
data = request.get_json(silent=True) or {}
44+
if 'salary' not in data:
45+
raise BadRequest('Missing field: salary')
46+
try:
47+
salary = float(data.get('salary'))
48+
except (TypeError, ValueError):
49+
raise BadRequest('Invalid salary')
50+
51+
# PERKESO的计算逻辑,具体费率需要参考官方数据
52+
employee_contribution = round(salary * 0.005, 2)
53+
employer_contribution = round(salary * 0.01, 2)
54+
total_contribution = round(employee_contribution + employer_contribution, 2)
55+
return jsonify({
56+
'employee_contribution': employee_contribution,
57+
'employer_contribution': employer_contribution,
58+
'total_contribution': total_contribution
59+
})
60+
61+
62+
# 4. PCB (Potongan Cukai Bulanan) 月度所得税计算
63+
@app.route('/pcb', methods=['POST'])
64+
def calculate_pcb():
65+
data = request.get_json(silent=True) or {}
66+
if 'salary' not in data:
67+
raise BadRequest('Missing field: salary')
68+
try:
69+
salary = float(data.get('salary'))
70+
except (TypeError, ValueError):
71+
raise BadRequest('Invalid salary')
72+
73+
# PCB的计算逻辑非常复杂,需要参考LHDN的官方指南
74+
# 这里我们只返回一个模拟数据
75+
pcb = round(salary * 0.1, 2)
76+
return jsonify({'pcb': pcb})
77+
78+
79+
# 5. 打卡功能
80+
@app.route('/clock_in', methods=['POST'])
81+
def clock_in():
82+
data = request.get_json(silent=True) or {}
83+
employee_id = data.get('employee_id')
84+
if not employee_id:
85+
raise BadRequest('Missing field: employee_id')
86+
# 这里需要记录打卡的时间和地点
87+
return jsonify({'message': 'Clock in successful'})
88+
89+
90+
# 6. 考勤表
91+
@app.route('/attendance', methods=['GET'])
92+
def get_attendance():
93+
employee_id = request.args.get('employee_id')
94+
if not employee_id:
95+
raise BadRequest('Missing query param: employee_id')
96+
# 这里需要从数据库中查询考勤记录
97+
attendance_records = [
98+
{'date': '2023-11-01', 'clock_in': '09:00', 'clock_out': '18:00'},
99+
{'date': '2023-11-02', 'clock_in': '09:05', 'clock_out': '17:55'}
100+
]
101+
return jsonify(attendance_records)
102+
103+
104+
# 7. 个人Payroll,加入Advance
105+
@app.route('/payroll', methods=['GET'])
106+
def get_payroll():
107+
employee_id = request.args.get('employee_id')
108+
if not employee_id:
109+
raise BadRequest('Missing query param: employee_id')
110+
# 这里需要从数据库中查询Payroll记录
111+
payroll_data = {
112+
'salary': 5000,
113+
'epf': 550,
114+
'perkeso': 50,
115+
'pcb': 500,
116+
'advance': 200,
117+
'net_salary': 4600
118+
}
119+
return jsonify(payroll_data)
120+
121+
122+
# 8. Advance 预支工资
123+
@app.route('/advance', methods=['POST'])
124+
def request_advance():
125+
data = request.get_json(silent=True) or {}
126+
employee_id = data.get('employee_id')
127+
amount = data.get('amount')
128+
if not employee_id:
129+
raise BadRequest('Missing field: employee_id')
130+
try:
131+
amount = float(amount)
132+
except (TypeError, ValueError):
133+
raise BadRequest('Invalid amount')
134+
# 这里需要记录预支工资的请求
135+
return jsonify({'message': 'Advance request submitted'})
136+
137+
138+
# 9. 个人资料
139+
@app.route('/profile', methods=['GET'])
140+
def get_profile():
141+
employee_id = request.args.get('employee_id')
142+
if not employee_id:
143+
raise BadRequest('Missing query param: employee_id')
144+
# 这里需要从数据库中查询个人资料
145+
profile_data = {
146+
'name': 'John Doe',
147+
'email': '[email protected]',
148+
'phone': '123-456-7890'
149+
}
150+
return jsonify(profile_data)
151+
152+
153+
# 10. 聊天功能
154+
@app.route('/chat', methods=['POST'])
155+
def send_message():
156+
data = request.get_json(silent=True) or {}
157+
sender_id = data.get('sender_id')
158+
receiver_id = data.get('receiver_id')
159+
message = data.get('message')
160+
if not sender_id or not receiver_id or not message:
161+
raise BadRequest('Missing sender_id, receiver_id or message')
162+
# 这里需要将消息保存到数据库中,并通知接收方
163+
return jsonify({'message': 'Message sent'})
164+
165+
166+
# 11. 语言翻译
167+
@app.route('/translate', methods=['POST'])
168+
def translate_text():
169+
data = request.get_json(silent=True) or {}
170+
text = data.get('text')
171+
target_language = data.get('target_language')
172+
if not text or not target_language:
173+
raise BadRequest('Missing text or target_language')
174+
# 这里需要调用翻译API,将文本翻译成目标语言
175+
# 这里我们只返回一个模拟数据
176+
translated_text = f'Translated to {target_language}: {text}'
177+
return jsonify({'translated_text': translated_text})
178+
179+
180+
@app.errorhandler(BadRequest)
181+
def handle_bad_request(err):
182+
return jsonify({'error': str(err)}), 400
183+
184+
185+
@app.route('/healthz')
186+
def healthz():
187+
return jsonify({'status': 'ok'})
188+
from flask import Flask, request, jsonify
189+
from werkzeug.exceptions import BadRequest
190+
from flask_cors import CORS
191+
192+
app = Flask(__name__)
193+
CORS(app)
194+
195+
9196
# In-memory data store for employees (for demo purposes)
10197
employees = {
11198
'E001': {
@@ -277,3 +464,8 @@ def healthz():
277464
# For local development; in production, use gunicorn with wsgi:app
278465
app.run(host='0.0.0.0', port=8000, debug=True)
279466

467+
468+
if __name__ == '__main__':
469+
# For local development; in production, use gunicorn with wsgi:app
470+
app.run(host='0.0.0.0', port=8000, debug=True)
471+

0 commit comments

Comments
 (0)