Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jmromer/salaries
A number-crunching API powered by Flask and Pandas
https://github.com/jmromer/salaries
demo flask numpy pandas python python3
Last synced: 4 days ago
JSON representation
A number-crunching API powered by Flask and Pandas
- Host: GitHub
- URL: https://github.com/jmromer/salaries
- Owner: jmromer
- Created: 2017-08-06T21:09:09.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-02-19T19:09:05.000Z (over 2 years ago)
- Last Synced: 2023-08-05T16:38:42.801Z (over 1 year ago)
- Topics: demo, flask, numpy, pandas, python, python3
- Language: Python
- Homepage:
- Size: 52.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
Awesome Lists containing this project
README
* salaries
[[https://circleci.com/gh/jkrmr/salaries][file:https://circleci.com/gh/jmromer/salaries.svg?style=svg]]
** Dependencies
- Python 3.6
- Flask API
- Pandas
- Nose (for testing)Install dependencies with ~pip install -r requirements.txt~.
** Local development
Start the API server running locally with ~python simple_api.py~.
** Architecture
*** API
Request-handling logic is contained in ~simple_api.py~:
#+BEGIN_SRC python
# simple_api.py L20-L30 (28e7228f)@app.route('/averages', methods=['GET'])
def averages():
averages = Salary.average_current_salaries(db.employees)
return jsonify(averages)@app.route('/headcount_over_time', methods=['GET'])
def headcount_over_time():
dept = request.args.get('department', '')
headcounts = Headcount.monthly_headcounts(db.employees, dept)
return jsonify(headcounts)
#+END_SRC
[[https://github.com/jkrmr/salaries/blob/28e7228f/simple_api.py#L20-L30][simple_api.py#L20-L30 (28e7228f)]]*** Namespaces
Logic for performing calculations on the given data set is housed in
[[https://github.com/jkrmr/salaries/blob/master/models/employee_headcount.py][models/employee_headcount.py]] and [[https://github.com/jkrmr/salaries/blob/master/models/employee_salary.py][models/employee_salary.py]].#+BEGIN_SRC python
# models/employee_headcount.py L34-45 (ddbd9c166a)def generate_headcounts_df(employees_list, department):
# yapf: disable
df = (pd
.DataFrame(employees_list)
.pipe(date_to_datetime)
.pipe(add_month_from_date)
.pipe(sort_by_month_keeping_latest)
.pipe(restrict_search_to_department, department)
.pipe(map_months_to_added_employee_counts)
.pipe(convert_added_employee_counts_to_cumulative_counts))
# yapf: enable
return df
#+END_SRC
[[https://github.com/jkrmr/salaries/blob/ddbd9c166a/models/employee_headcount.py#L34-L45][models/employee_headcount.py L34-45 (ddbd9c166a)]]** Tests
Tests are included in the ~tests~ directory and can be run locally with
~nosetests tests~.#+BEGIN_SRC python
# tests/employee_headcount_test.py L92-L113 (28e7228f)def test_counts_only_most_recent_entry_for_an_employee_within_month(self):
employees = [{
'date': '2015-01-01',
'employee': 2,
'salary': 10,
'dept': 'Engineering'
}, {
'date': '2015-01-15',
'employee': 2,
'salary': 10,
'dept': 'Design'
}, {
'date': '2015-02-15',
'employee': 3,
'salary': 10,
'dept': 'Engineering'
}]headcount = Headcount.monthly_headcounts(employees, 'engineering')
expected = {'data': [{'month': '2015-02-01', 'headcount': 1}]}
assert_equal(headcount, expected)
#+END_SRC
[[https://github.com/jkrmr/salaries/blob/28e7228f/tests/employee_headcount_test.py#L92-L113][tests/employee_headcount_test.py#L92-L113 (28e7228f)]]