Skip to content

Commit

Permalink
fix temporal chart bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yuqizhang99 committed Jul 4, 2023
1 parent b46286f commit 1dc88dd
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
53 changes: 52 additions & 1 deletion digautoprofiler/profile_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,57 @@ def getTemporalMeta(colData: pd.Series):
result = "ascending"
elif colData.is_monotonic_decreasing:
result = "descending"
else:
result = "noSort"
return {"sortedness": result}

def getAggrData(dfName: pd.DataFrame, catColName: str, quantColName: str, aggrType: str="mean", n=10):
"""
aggrType is one of ["mean", "sum", "count", "min", "max"]
"""
aggrData = dfName.groupby(catColName).agg({quantColName: aggrType})[quantColName].sort_values(ascending=False)[:n]
print(aggrData.to_json())


def getTempAggrData(dfName: pd.DataFrame, tempColName: str, quantColName: str, aggrType: str="count"):
"""
timestep kwarg must be one of ["Y","M","W","D","H","T","S"]
"""
# sturge's rule
binNum = min(round(1 + 3.322 * math.log10(len(dfName))),20)
offsetAliases = ['Y','M','W','D','H','T','S']
i = 0
previousLen = -float("inf")
currentLen = len(dfName[tempColName].dt.to_period(offsetAliases[i]).unique())
while i < len(offsetAliases) and currentLen < binNum and currentLen > previousLen:
previousLen = currentLen
currentLen = len(dfName[tempColName].dt.to_period(offsetAliases[i]).unique())
i += 1
if currentLen <= previousLen:
timestep = offsetAliases[max(i - 2,0)]
else:
timestep = offsetAliases[max(i - 1,0)]

indices = dfName[tempColName].dt.to_period(timestep).astype('string')
groups = pd.Series(dfName[quantColName].tolist(),index=indices).groupby(level=0)
if aggrType == "mean":
tempAggrData = groups.mean()
if aggrType == "count":
tempAggrData = groups.count()
if aggrType == "sum":
tempAggrData = groups.sum()
if aggrType == "min":
tempAggrData = groups.min()
if aggrType == "max":
tempAggrData = groups.max()
print(json.dumps({"data":tempAggrData.to_dict(), "timestep":timestep}))

def getTemporalMeta(colData: pd.Series):
if colData.is_monotonic_increasing:
result = "ascending"
elif colData.is_monotonic_decreasing:
result = "descending"

else:
result = "noSort"
vc = colData.value_counts()
Expand Down Expand Up @@ -282,7 +333,7 @@ def getTempAggrData(dfName: pd.DataFrame, tempColName: str, quantColName: str, a
offsetAliases = ['Y','M','W','D','H','T','S']
i = 0
previousLen = -float("inf")
currentLen = 0
currentLen = len(dfName[tempColName].dt.to_period(offsetAliases[i]).unique())
while i < len(offsetAliases) and currentLen < binNum and currentLen > previousLen:
previousLen = currentLen
currentLen = len(dfName[tempColName].dt.to_period(offsetAliases[i]).unique())
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@
]
}
}
}
}
2 changes: 1 addition & 1 deletion src/components/create-chart/DropdownMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
export let clickable: boolean = true;
export let title = 'Select a column';
export let selectedColumnName: string = undefined;
let displayGroups: string[];
function determineGroup(column: IColTypeTuple) {
Expand Down

0 comments on commit 1dc88dd

Please sign in to comment.