-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
naipawat.poo@student.mahidol.ac.th
committed
Jan 23, 2020
1 parent
a21fb9a
commit 28153a1
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,3 +55,4 @@ | |
/127/README.md | ||
/223/README.md | ||
/30/README.md | ||
/258/README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import csv | ||
|
||
import pandas as pd | ||
import math | ||
XYZ = "https://bites-data.s3.us-east-2.amazonaws.com/xyz.csv" | ||
THRESHOLDS = (5000, 0.05) | ||
|
||
|
||
def calculate_flux(XYZ: str) -> list: | ||
"""Read the data in from xyz.csv | ||
add two new columns, one to calculate dollar flux, | ||
and the other to calculate percentage flux | ||
return as a list of tuples | ||
""" | ||
data = pd.read_csv(XYZ) | ||
data['Dollar Flux'] = data['12/31/20']-data['12/31/19'] | ||
data['Percentage Flux'] = data['Dollar Flux']/data['12/31/19'] | ||
return list(zip(data['Account'],data['12/31/20'],data['12/31/19'],data['Dollar Flux'],data['Percentage Flux'])) | ||
|
||
|
||
def identify_flux(xyz: list) -> list: | ||
"""Load the list of tuples, iterate through | ||
each item and determine if it is above both | ||
thresholds. if so, add to the list | ||
""" | ||
flagged_lines = [] | ||
for key, value in enumerate(xyz): | ||
account,year1,year2,dollar_flux,percentage_flux = value | ||
if abs(dollar_flux)>THRESHOLDS[0] and abs(percentage_flux)>THRESHOLDS[1]: | ||
flagged_lines.append(xyz[key]) | ||
return flagged_lines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from flux import XYZ, calculate_flux, identify_flux | ||
|
||
|
||
def test_calculate(): | ||
calc = calculate_flux(XYZ) | ||
assert isinstance(calc, list) | ||
assert len(calc) == 11 | ||
assert len(calc[0]) == 5 | ||
|
||
*orig, dol, perc = calc[0] | ||
assert orig == ["Cash", 120000, 115000] | ||
assert dol == 5000 | ||
assert round(perc, 2) == 0.04 | ||
|
||
|
||
def test_identify(): | ||
flux = identify_flux(calculate_flux(XYZ)) | ||
assert isinstance(flux, list) | ||
assert len(flux) == 5 | ||
assert [act for act, *_ in flux] == [ | ||
"Accounts Receivable", | ||
"Inventory", | ||
"Notes Receivable", | ||
"Accrued Payroll", | ||
"Retained Earnings", | ||
] |