Răsfoiți Sursa

Added a sample for decimation (#1946)

* Added a sample for decimation
Fabien Lelaquais 7 luni în urmă
părinte
comite
e0db1b85d1

+ 85 - 0
doc/gui/examples/charts/advanced_large_datasets.py

@@ -0,0 +1,85 @@
+# Copyright 2021-2024 Avaiga Private Limited
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+#        http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations under the License.
+# -----------------------------------------------------------------------------------------
+# To execute this script, make sure that the taipy-gui package is installed in your
+# Python environment and run:
+#     python <script>
+# -----------------------------------------------------------------------------------------
+from enum import Enum
+
+import numpy as np
+import pandas as pd
+
+from taipy.gui import Gui
+from taipy.gui.data.decimator import MinMaxDecimator
+
+
+# Processing techniques
+class Processing(Enum):
+    # Don't process the data
+    NONE = 0
+    # Sub-sample the dataset
+    SUB_SAMPLING = 1
+    # Compute local average in the dataset
+    AVERAGE = 2
+    # Use decimation
+    DECIMATION = 3
+
+
+# Choose a processing technique
+processing = Processing.DECIMATION
+
+# Generate a random dataset
+#   Compute the 'X' data
+#     Generate 50000 x values (a sequence of integers)
+x_values = np.linspace(1, 100, 50000)
+
+#   Compute the 'Y' data
+#     Define the combined log-sine function
+y_values = np.log(x_values) * np.sin(x_values / 5)
+#   Introduce some noise
+#     Create a mask with a True value with a 1 % probability
+noise_mask = np.random.rand(*y_values.shape) < 0.01
+#     The noise values
+noise_values = np.random.uniform(-0.5, 0.5, size=np.sum(noise_mask))
+#     Add the noise to the 'Y' values
+y_values_noise = np.copy(y_values)  # Copy original array
+y_values_noise[noise_mask] += noise_values
+
+# Use no decimator by default
+decimator = None
+
+# Transform the 'Y' dataset with the chosen processing technique
+if processing == Processing.SUB_SAMPLING:
+    # Pick one every 100 data points
+    x_values = x_values[::100]
+    y_values_noise = y_values_noise[::100]
+
+elif processing == Processing.AVERAGE:
+    # Average of 100 successive values
+    x_values = x_values[::100]
+    y_values_noise = y_values_noise.reshape(-1, 100)
+    # Compute the average of each group of 100 values
+    y_values_noise = np.mean(y_values_noise, axis=1)
+
+elif processing == Processing.DECIMATION:
+    # Use Taipy's decimation processing
+    decimator = MinMaxDecimator(200)
+
+print(f"Using {str(processing)}: Dataset has {y_values_noise.size} data points")  # noqa: F401, T201
+
+# Create the DataFrame
+data = pd.DataFrame({"X": x_values, "Y": y_values_noise})
+
+page = "<|{data}|chart|x=X|y=Y|mode=lines|decimator=decimator|>"
+
+if __name__ == "__main__":
+    Gui(page).run(title="Chart - Advanced - Large datasets")

+ 36 - 0
doc/gui/examples/controls/table_custom_format.py

@@ -0,0 +1,36 @@
+# Copyright 2021-2024 Avaiga Private Limited
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+#        http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations under the License.
+# -----------------------------------------------------------------------------------------
+# To execute this script, make sure that the taipy-gui package is installed in your
+# Python environment and run:
+#     python <script>
+# -----------------------------------------------------------------------------------------
+from taipy.gui import Gui, Markdown
+
+data = {
+    "User Name": ["johndoe", "janedoe", "admin", "sampleuser", "guestaccount"],
+    "Password": ["Password123!", "Test@2023", "Admin#789", "SamplePass#1", "Guest!2024"],
+}
+
+
+def hide_text(p0, p1, p2, p3, p4):
+    return "*" * 8
+
+
+def hide_text2(_1, _2, index, _3, _4):
+    return "*" * 8
+
+
+page = Markdown("<|{data}|table|format_fn[Password]=hide_text|editable[Password]|show_all|no on_add|no on_delete|>")
+
+
+if __name__ == "__main__":
+    Gui(page).run(title="Table - Custom formatting")

+ 3 - 1
doc/gui/examples/controls/table_guard_edits.py

@@ -20,7 +20,8 @@ import requests
 from taipy.gui import Gui, State, notify
 
 # The RandomAPI API used to generate random user names
-randomuser_url = 'https://randomuser.me/api'
+randomuser_url = "https://randomuser.me/api"
+
 
 # Create a random person name and salary
 def pick_user() -> tuple[str, int]:
@@ -44,6 +45,7 @@ def pick_user() -> tuple[str, int]:
     print("ERROR: Could not invoke the Random User Generator API")  # noqa: F401, T201
     return ("ERROR", 0)
 
+
 # Generate four random persons with their salary expectation and store them in a dictionary
 candidates: dict[str, list] = {"Name": [], "Salary": []}
 for candidate in [pick_user() for _ in range(4)]:

+ 1 - 1
doc/gui/examples/styling_dynamic.py

@@ -57,4 +57,4 @@ Enter a five-letter word:
 )
 
 if __name__ == "__main__":
-    Gui(page).run()
+    Gui(page).run(title="Styling - Dynamic styling")

+ 1 - 1
taipy/gui/page.py

@@ -160,7 +160,7 @@ class Page:
           }
           "class2": {
             "class3": {
-                "css_property2": "css_value2",
+              "css_property2": "css_value2",
             }
           }
         }