Skip to content

Commit

Permalink
bites 258
Browse files Browse the repository at this point in the history
  • Loading branch information
naipawat.poo@student.mahidol.ac.th committed Jan 23, 2020
1 parent a21fb9a commit 28153a1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@
/127/README.md
/223/README.md
/30/README.md
/258/README.md
31 changes: 31 additions & 0 deletions 258/flux.py
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
26 changes: 26 additions & 0 deletions 258/test_flux.py
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",
]

0 comments on commit 28153a1

Please sign in to comment.