Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/weiyu0824/fetch-result-test
https://github.com/weiyu0824/fetch-result-test
Last synced: 11 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/weiyu0824/fetch-result-test
- Owner: weiyu0824
- Created: 2023-02-02T18:38:41.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-02-07T17:00:17.000Z (almost 2 years ago)
- Last Synced: 2023-05-11T15:27:53.137Z (over 1 year ago)
- Language: Python
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Fetch Result Test
This is the repo for Fetch Result Test (Backend)## How to run the code
- Run code
```
python3 spend_points.py
```- Run unit test
```
python3 spend_points_test.py
```## Design
### Logic
To my understanding, those records with negative points in the CSV file means the user spend that amount of points from the payer. Thus, we should make sure that the user has enough points from that payer when he/she is about to spend points.
```
# My understanding
"DANNON", 1000, "2020-11-02T14:00:00Z" # The user got 1000 points from DANNON
"DANNON", -200, "2020-11-02T14:00:00Z" # The user spend 200 points that comes from DANNON
``````
# Good example
"DANNON", 1000, "2020-11-02T14:00:00Z"
"DANNON", -200, "2020-11-02T14:00:00Z"# Bad example
"DANNON", 100, "2020-11-02T14:00:00Z"
"DANNON", -200, "2020-11-02T14:00:00Z"
```### Flow
This simple program contains several steps.
1. Read the CSV file
2. Preprocess the records
3. Calculate the result```
# Preprocess
# sort -> process records with negative points# Before preprocess
"DANNON", -100, "2020-11-02T14:00:00Z"
"DANNON", 200, "2020-11-01T14:00:00Z"# After preprocess
"DANNON", 100, "2020-11-01T14:00:00Z"
"DANNON", 0, "2020-11-02T14:00:00Z"
```