Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bivariate #139

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this doing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the initial value of currentLen is wrong, which is the reason why the temporal chart sometimes can not determine the number of bins well

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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase off main, this should not get deleted

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
Loading