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

Preconfig conditional format #1259

Merged
merged 26 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
201b9f7
mitosheet: pre-config-formatting
aarondr77 Mar 10, 2024
f6e7e52
Merge branch 'better-default-number-formatting-1' into preconfig-cond…
aarondr77 Mar 10, 2024
3f62cf8
mitosheet: update app
aarondr77 Mar 10, 2024
63b4970
mitosheet: move column definitions to preprocessing
aarondr77 Mar 11, 2024
73b32f2
mitosheet: fix types
aarondr77 Mar 12, 2024
9171fbd
mitosheet: fix up tests
aarondr77 Mar 12, 2024
62b82e6
mitosheet: create new preprocessing step type
aarondr77 Mar 12, 2024
4043cc5
mitosheet: create sample app for testing
aarondr77 Mar 12, 2024
1dbfa8e
mitosheet: add basic test
aarondr77 Mar 12, 2024
f8a7ca8
mitosheet: create more tests
aarondr77 Mar 12, 2024
932fb35
mitosheet: fix types for python 3.6
aarondr77 Mar 12, 2024
a76069c
mitosheet: move out of preprocessing steps
aarondr77 Mar 12, 2024
4526f4e
mitosheet: new list for each dataframe
aarondr77 Mar 12, 2024
c612824
mitosheet: more error handling
aarondr77 Mar 12, 2024
ab73c09
mitosheet: more error handling and testing
aarondr77 Mar 12, 2024
174c349
mitosheet: add more tests
aarondr77 Mar 12, 2024
a48e878
mitosheet: cleanup
aarondr77 Mar 12, 2024
9e9f99b
mitosheet: fix all mypy issues
aarondr77 Mar 12, 2024
786f996
trymito: add back test
aarondr77 Mar 12, 2024
e1e548b
mitosheet: fix types
aarondr77 Mar 12, 2024
a4cfb21
mitosheet: fix failing streamlit test
aarondr77 Mar 12, 2024
d790393
mitosheet: tiny cleanup
aarondr77 Mar 13, 2024
ca0e964
Merge branch 'dev' into preconfig-conditional-format
aarondr77 Mar 13, 2024
c9b7923
mitosheet: paramaterize tests
aarondr77 Mar 13, 2024
4b72aee
mitosheet: address review
aarondr77 Mar 13, 2024
a487a74
mitosheet: fix failing pytest
aarondr77 Mar 13, 2024
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
14 changes: 13 additions & 1 deletion mitosheet/mitosheet/mito_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from mitosheet.steps_manager import StepsManager
from mitosheet.telemetry.telemetry_utils import (log, log_event_processed,
telemetry_turned_on)
from mitosheet.types import CodeOptions, MitoTheme, ParamMetadata
from mitosheet.types import CodeOptions, ConditionalFormat, MitoTheme, ParamMetadata
from mitosheet.updates.replay_analysis import REPLAY_ANALYSIS_UPDATE
from mitosheet.user.create import try_create_user_json_file
from mitosheet.user.db import USER_JSON_PATH, get_user_field
Expand Down Expand Up @@ -57,6 +57,7 @@ def __init__(
user_defined_importers: Optional[List[Callable]]=None,
user_defined_editors: Optional[List[Callable]]=None,
code_options: Optional[CodeOptions]=None,
partial_conditional_formats: Optional[List[Dict[str, Any]]]=None,
theme: Optional[MitoTheme]=None,
):
"""
Expand Down Expand Up @@ -92,6 +93,16 @@ def __init__(

if not os.path.exists(import_folder):
raise ValueError(f"Import folder {import_folder} does not exist. Please change the file path or create the folder.")


conditional_formats = [{
'format_uuid': 'preset_conditional_format',
'columnIDs': partial_conditional_formats['columnHeaders'],
'filters': [partial_conditional_formats['filters']],
'invalidFilterColumnIDs': [],
'color': partial_conditional_formats['color'],
'backgroundColor': partial_conditional_formats['backgroundColor']
}]

# Set up the state container to hold private widget state
self.steps_manager = StepsManager(
Expand All @@ -104,6 +115,7 @@ def __init__(
user_defined_importers=all_custom_importers,
user_defined_editors=user_defined_editors,
code_options=code_options,
conditional_formats=conditional_formats,
theme=theme
)

Expand Down
3 changes: 3 additions & 0 deletions mitosheet/mitosheet/pro/conditional_formatting_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def get_conditonal_formatting_result(
formatted_result: ConditionalFormattingCellResults = dict()

for conditional_format in conditional_formatting_rules:
print(conditional_format)
try:

format_uuid = conditional_format["format_uuid"]
Expand Down Expand Up @@ -52,7 +53,9 @@ def get_conditonal_formatting_result(
# are sent to the frontend
json_index = json.dumps(index, cls=NpEncoder)
formatted_result[column_id][json_index] = {'backgroundColor': backgroundColor, 'color': color}

except Exception as e:
print("IN THIS EXCEPTION")
if format_uuid not in invalid_conditional_formats:
invalid_conditional_formats[format_uuid] = []
invalid_conditional_formats[format_uuid].append(column_id)
Expand Down
2 changes: 1 addition & 1 deletion mitosheet/mitosheet/step_performers/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,5 @@ def check_filters_contain_condition_that_needs_full_df(filters: List[Union[Filte
filter_group: FilterGroup = filter_or_group #type: ignore
if check_filters_contain_condition_that_needs_full_df(filter_group["filters"]):
return True

return False
17 changes: 15 additions & 2 deletions mitosheet/mitosheet/steps_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from mitosheet.enterprise.mito_config import MitoConfig
from mitosheet.enterprise.telemetry.mito_log_uploader import MitoLogUploader
from mitosheet.experiments.experiment_utils import get_current_experiment
from mitosheet.pro.conditional_formatting_utils import get_conditonal_formatting_result
from mitosheet.step_performers.column_steps.set_column_formula import get_user_defined_sheet_function_objects
from mitosheet.step_performers.import_steps.dataframe_import import DataframeImportStepPerformer
from mitosheet.step_performers.import_steps.excel_range_import import ExcelRangeImportStepPerformer
Expand All @@ -35,7 +36,7 @@
SnowflakeImportStepPerformer
from mitosheet.transpiler.transpile import transpile
from mitosheet.transpiler.transpile_utils import get_default_code_options
from mitosheet.types import CodeOptions, MitoTheme, ParamMetadata
from mitosheet.types import CodeOptions, ConditionalFormat, MitoTheme, ParamMetadata
from mitosheet.updates import UPDATES
from mitosheet.user.utils import is_enterprise, is_running_test
from mitosheet.utils import NpEncoder, dfs_to_array_for_json, get_new_id, is_default_df_names
Expand Down Expand Up @@ -187,6 +188,7 @@ def __init__(
user_defined_importers: Optional[List[Callable]]=None,
user_defined_editors: Optional[List[Callable]]=None,
code_options: Optional[CodeOptions]=None,
conditional_formats: Optional[List[ConditionalFormat]]=None,
theme: Optional[MitoTheme]=None,
):
"""
Expand Down Expand Up @@ -265,12 +267,23 @@ def __init__(
df_names=df_names,
user_defined_functions=self.user_defined_functions,
user_defined_importers=self.user_defined_importers,
user_defined_editors=self.user_defined_editors
user_defined_editors=self.user_defined_editors,
),
{}
)
]

df_formats = {
'columns': {},
'headers': {},
'rows': {'even': {}, 'odd': {}},
'border': {},
'conditional_formats': conditional_formats
}

self.steps_including_skipped[0].df_formats[0] = df_formats
self.steps_including_skipped[0].post_state.df_formats[0] = df_formats

"""
To help with redo, we store a list of a list of the steps that
existed in the step manager before the user clicked undo or reset,
Expand Down
10 changes: 9 additions & 1 deletion mitosheet/mitosheet/streamlit/v1/spreadsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from mitosheet.mito_backend import MitoBackend
from mitosheet.selection_utils import get_selected_element
from mitosheet.types import CodeOptions, ParamMetadata, ParamType
from mitosheet.types import CodeOptions, ConditionalFormat, ParamMetadata, ParamType
from mitosheet.utils import get_new_id

CURRENT_MITO_ANALYSIS_VERSION = 1
Expand Down Expand Up @@ -118,12 +118,14 @@ def __init__(
self,
code: str,
code_options: Optional[CodeOptions],
conditional_formats: Optional[List[Dict[str, Any]]],
fully_parameterized_function: str,
param_metadata: List[ParamMetadata],
mito_analysis_version: int=CURRENT_MITO_ANALYSIS_VERSION
):
self.__code = code
self.__code_options = code_options
self.__conditional_formats = conditional_formats
self.__fully_parameterized_function = fully_parameterized_function
self.__param_metadata = param_metadata
self.mito_analysis_version = mito_analysis_version
Expand All @@ -143,6 +145,7 @@ def to_json(self) -> str:
return json.dumps({
'code': self.__code,
'code_options': self.__code_options,
'conditional_formats': self.__conditional_formats,
'fully_parameterized_function': self.__fully_parameterized_function,
'param_metadata': self.__param_metadata,
'mito_analysis_version': self.mito_analysis_version
Expand All @@ -158,6 +161,7 @@ def from_json(json_str: str) -> 'RunnableAnalysis':
return RunnableAnalysis(
json_dict['code'],
json_dict['code_options'],
json_dict['conditional_formats'],
json_dict['fully_parameterized_function'],
json_dict['param_metadata'],
mito_analysis_version=json_dict['mito_analysis_version']
Expand Down Expand Up @@ -269,6 +273,7 @@ def _get_mito_backend(
_editors: Optional[List[Callable]]=None,
_sheet_functions: Optional[List[Callable]]=None,
_code_options: Optional[CodeOptions]=None,
_conditional_formats: Optional[Dict[str, Any]]=None,
import_folder: Optional[str]=None,
df_names: Optional[List[str]]=None,
session_id: Optional[str]=None,
Expand All @@ -280,6 +285,7 @@ def _get_mito_backend(
import_folder=import_folder,
user_defined_importers=_importers, user_defined_functions=_sheet_functions, user_defined_editors=_editors,
code_options=_code_options,
partial_conditional_formats=_conditional_formats,
)

# Make a send function that stores the responses in a list
Expand Down Expand Up @@ -320,6 +326,7 @@ def spreadsheet( # type: ignore
df_names: Optional[List[str]]=None,
import_folder: Optional[str]=None,
code_options: Optional[CodeOptions]=None,
conditional_formats: Optional[Dict[str, Any]]=None,
return_type: str='default',
height: Optional[str]=None,
key=None
Expand Down Expand Up @@ -366,6 +373,7 @@ def spreadsheet( # type: ignore
_importers=importers,
_editors=editors,
_code_options=code_options,
_conditional_formats=conditional_formats,
import_folder=import_folder,
session_id=session_id,
df_names=df_names,
Expand Down
22 changes: 22 additions & 0 deletions mitosheet/target-streamlit-app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import streamlit as st
from mitosheet.streamlit.v1 import spreadsheet
import pandas as pd

st.set_page_config(layout="wide")

st.title('SKU analysis app')

df = pd.read_csv('./SKU.csv')
new_dfs, code = spreadsheet(
df,
conditional_formats={
'columnHeaders': ['quantity'],
'filters': {
'condition': 'greater_than_or_equal',
'value': 5
},
'backgroundColor': '#ffc9bb',
'color': '#c61a09'
},
height='900px'
)
Loading