Skip to content

Commit

Permalink
feat: send to brackground when "User limit exceed" (#74)
Browse files Browse the repository at this point in the history
* feat: send to brackground when "User limit exceed"

* test: change scale
  • Loading branch information
dfguerrerom authored Nov 21, 2024
1 parent c760105 commit aaf6ad0
Show file tree
Hide file tree
Showing 5 changed files with 349 additions and 11 deletions.
13 changes: 9 additions & 4 deletions component/scripts/deferred_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,23 @@ def perform_calculation(

tasks[process_id] = ee.Feature(None, process).set("process_id", process_id)

if not background:
if not background and all_succeeded:
try:
if test_time_out:
raise Exception("Computation timed out.")

result: Union[SubAYearDict, SubBYearDict] = process.getInfo()

logger.set_msg(f"Calculating {process_id}... Done.", id_=process_id)
logger.set_state("success", id_=process_id)
results[process_id] = result

except Exception as e:
if "Computation timed out." in str(e):
if "Computation timed out." in str(
e
) or "User memory limit exceeded" in str(e):
logger.set_msg(
f"Warning: {process_id} failed on the fly, it will be processed on the background.",
f"Warning: {process_id} failed on the fly. All tasks will be processed on the background. Skipping...",
id_=process_id,
)
logger.set_state("warning", id_=process_id)
Expand All @@ -117,7 +121,8 @@ def perform_calculation(
raise Exception(f"There was an error trying to compute {e}")

all_succeeded = False
else:

elif background:
all_succeeded = False
logger.set_msg(
f"{process_id} has been scheduled for background processing.",
Expand Down
5 changes: 3 additions & 2 deletions component/widget/transition_matrix.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Tuple
import concurrent.futures
import ipyvuetify as v
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -278,7 +278,8 @@ def disable_edition(self, change):
create execute them as a pool executor"""

selectables = self.get_children(id_="impact")
[setattr(s, "disabled", not s.disabled) for s in selectables]
with concurrent.futures.ThreadPoolExecutor() as executor:
executor.map(lambda s: setattr(s, "disabled", not s.disabled), selectables)

def truncate_string(self, string):
"""truncate the content if it's too long"""
Expand Down
331 changes: 331 additions & 0 deletions tests/test_scripts/delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,331 @@
{
"2000": {
"sub_a": [
{
"biobelt": 2,
"groups": [
{"lc": 4, "sum": 13.820592750000003},
{"lc": 5, "sum": 10.858824125000003},
],
},
{
"biobelt": 3,
"groups": [
{"lc": 1, "sum": 2.9620139375},
{"lc": 2, "sum": 443.4437093313726},
{"lc": 3, "sum": 3.949392375},
{"lc": 4, "sum": 3009.7269348894515},
{"lc": 5, "sum": 295.9681743750002},
],
},
{
"biobelt": 4,
"groups": [
{"lc": 1, "sum": 177.75635406249978},
{"lc": 10, "sum": 71.09126168750002},
{"lc": 2, "sum": 3282.3606984561216},
{"lc": 3, "sum": 34.5573553125},
{"lc": 4, "sum": 30421.925989617663},
{"lc": 5, "sum": 2861.0745937198485},
{"lc": 6, "sum": 17.767890937500002},
{"lc": 8, "sum": 0.9865298125},
],
},
]
},
"2000_2015_2018": {
"baseline_degradation": [
{"biobelt": 2, "groups": [{"lc": 2, "sum": 24.679416875000005}]},
{
"biobelt": 3,
"groups": [
{"lc": 1, "sum": 17.7640129375},
{"lc": 2, "sum": 3648.4336088521964},
{"lc": 3, "sum": 89.85260311862748},
],
},
{
"biobelt": 4,
"groups": [
{"lc": 1, "sum": 1141.8429471443653},
{"lc": 2, "sum": 34885.91375620788},
{"lc": 3, "sum": 839.7639702534314},
],
},
],
"baseline_transition": [
{
"biobelt": 2,
"groups": [
{"lc": 404, "sum": 13.820592750000003},
{"lc": 505, "sum": 10.858824125000003},
],
},
{
"biobelt": 3,
"groups": [
{"lc": 101, "sum": 2.9620139375},
{"lc": 202, "sum": 389.1013299627452},
{"lc": 204, "sum": 53.35597561862745},
{"lc": 205, "sum": 0.98640375},
{"lc": 303, "sum": 2.963043},
{"lc": 304, "sum": 0.986349375},
{"lc": 402, "sum": 5.9248219375},
{"lc": 404, "sum": 2991.962921951953},
{"lc": 405, "sum": 11.839191000000001},
{"lc": 504, "sum": 34.52387437499999},
{"lc": 505, "sum": 261.4443000000002},
],
},
{
"biobelt": 4,
"groups": [
{"lc": 1001, "sum": 1.9751745},
{"lc": 1006, "sum": 0.9876119375},
{"lc": 1008, "sum": 0.9874464375},
{"lc": 101, "sum": 177.7563540624998},
{"lc": 1010, "sum": 67.14102881250001},
{"lc": 201, "sum": 25.67471225},
{"lc": 202, "sum": 2726.6558874735297},
{"lc": 204, "sum": 524.107992545098},
{"lc": 205, "sum": 5.9221061875},
{"lc": 301, "sum": 9.875537062500001},
{"lc": 303, "sum": 23.694438687500003},
{"lc": 304, "sum": 0.9873795625},
{"lc": 401, "sum": 29.6276235},
{"lc": 402, "sum": 479.70225030465605},
{"lc": 403, "sum": 1.9744893125},
{"lc": 404, "sum": 29335.37694097355},
{"lc": 405, "sum": 573.2697612772057},
{"lc": 406, "sum": 0.9876119375},
{"lc": 410, "sum": 0.9873123125},
{"lc": 501, "sum": 3.9503930625000003},
{"lc": 502, "sum": 11.8425818125},
{"lc": 504, "sum": 308.7464919583334},
{"lc": 505, "sum": 2536.535126886516},
{"lc": 601, "sum": 0.98846475},
{"lc": 603, "sum": 0.9869009375},
{"lc": 606, "sum": 15.79252525},
{"lc": 808, "sum": 0.9865298125},
],
},
],
"final_degradation": [
{"biobelt": 2, "groups": [{"lc": 2, "sum": 24.679416875000005}]},
{
"biobelt": 3,
"groups": [
{"lc": 1, "sum": 23.6917688125},
{"lc": 2, "sum": 3727.426198283324},
{"lc": 3, "sum": 4.9322578125},
],
},
{
"biobelt": 4,
"groups": [
{"lc": 1, "sum": 1479.1317014845606},
{"lc": 2, "sum": 35347.91660387111},
{"lc": 3, "sum": 40.472368249999995},
],
},
],
"report_transition": [
{
"biobelt": 2,
"groups": [
{"lc": 404, "sum": 13.820592750000003},
{"lc": 505, "sum": 10.858824125000003},
],
},
{
"biobelt": 3,
"groups": [
{"lc": 101, "sum": 2.9620139375},
{"lc": 202, "sum": 393.0528875877452},
{"lc": 204, "sum": 1.9732643125},
{"lc": 303, "sum": 2.963043},
{"lc": 402, "sum": 4.9416955625},
{"lc": 404, "sum": 3073.913606570578},
{"lc": 405, "sum": 1.9738191875},
{"lc": 504, "sum": 3.946752375},
{"lc": 505, "sum": 270.3231423750002},
],
},
{
"biobelt": 4,
"groups": [
{"lc": 101, "sum": 249.84825918750008},
{"lc": 1010, "sum": 68.128341125},
{"lc": 202, "sum": 3198.44996496568},
{"lc": 204, "sum": 18.7624734375},
{"lc": 205, "sum": 0.9882811875},
{"lc": 303, "sum": 26.6558289375},
{"lc": 401, "sum": 0.9878878125},
{"lc": 402, "sum": 166.32392662401958},
{"lc": 404, "sum": 29816.139113449248},
{"lc": 405, "sum": 184.78160059117673},
{"lc": 406, "sum": 0.9862765625},
{"lc": 502, "sum": 0.986055875},
{"lc": 504, "sum": 36.513331125},
{"lc": 505, "sum": 3078.2276073512226},
{"lc": 601, "sum": 0.9870568125},
{"lc": 606, "sum": 16.7806923125},
{"lc": 808, "sum": 1.9739762500000002},
],
},
],
},
"2000_2015_2021": {
"baseline_degradation": [
{"biobelt": 2, "groups": [{"lc": 2, "sum": 24.679416875000005}]},
{
"biobelt": 3,
"groups": [
{"lc": 1, "sum": 17.7640129375},
{"lc": 2, "sum": 3648.4336088521964},
{"lc": 3, "sum": 89.85260311862748},
],
},
{
"biobelt": 4,
"groups": [
{"lc": 1, "sum": 1141.8429471443653},
{"lc": 2, "sum": 34885.91375620788},
{"lc": 3, "sum": 839.7639702534314},
],
},
],
"baseline_transition": [
{
"biobelt": 2,
"groups": [
{"lc": 404, "sum": 13.820592750000003},
{"lc": 505, "sum": 10.858824125000003},
],
},
{
"biobelt": 3,
"groups": [
{"lc": 101, "sum": 2.9620139375},
{"lc": 202, "sum": 389.1013299627452},
{"lc": 204, "sum": 53.35597561862745},
{"lc": 205, "sum": 0.98640375},
{"lc": 303, "sum": 2.963043},
{"lc": 304, "sum": 0.986349375},
{"lc": 402, "sum": 5.9248219375},
{"lc": 404, "sum": 2991.9629219519525},
{"lc": 405, "sum": 11.839191000000001},
{"lc": 504, "sum": 34.52387437499999},
{"lc": 505, "sum": 261.44430000000017},
],
},
{
"biobelt": 4,
"groups": [
{"lc": 1001, "sum": 1.9751745},
{"lc": 1006, "sum": 0.9876119375},
{"lc": 1008, "sum": 0.9874464375},
{"lc": 101, "sum": 177.75635406249978},
{"lc": 1010, "sum": 67.14102881250001},
{"lc": 201, "sum": 25.67471225},
{"lc": 202, "sum": 2726.655887473529},
{"lc": 204, "sum": 524.107992545098},
{"lc": 205, "sum": 5.9221061875},
{"lc": 301, "sum": 9.875537062500001},
{"lc": 303, "sum": 23.694438687500003},
{"lc": 304, "sum": 0.9873795625},
{"lc": 401, "sum": 29.6276235},
{"lc": 402, "sum": 479.7022503046561},
{"lc": 403, "sum": 1.9744893125},
{"lc": 404, "sum": 29335.37694097355},
{"lc": 405, "sum": 573.2697612772058},
{"lc": 406, "sum": 0.9876119375},
{"lc": 410, "sum": 0.9873123125},
{"lc": 501, "sum": 3.9503930625000003},
{"lc": 502, "sum": 11.8425818125},
{"lc": 504, "sum": 308.7464919583334},
{"lc": 505, "sum": 2536.5351268865156},
{"lc": 601, "sum": 0.98846475},
{"lc": 603, "sum": 0.9869009375},
{"lc": 606, "sum": 15.79252525},
{"lc": 808, "sum": 0.9865298125},
],
},
],
"final_degradation": [
{"biobelt": 2, "groups": [{"lc": 2, "sum": 24.679416875000005}]},
{
"biobelt": 3,
"groups": [
{"lc": 1, "sum": 63.18494038357843},
{"lc": 2, "sum": 3673.4929126372463},
{"lc": 3, "sum": 19.372371887499998},
],
},
{
"biobelt": 4,
"groups": [
{"lc": 1, "sum": 1806.4468736115193},
{"lc": 2, "sum": 34541.280107391816},
{"lc": 3, "sum": 519.7936926024496},
],
},
],
"report_transition": [
{
"biobelt": 2,
"groups": [
{"lc": 404, "sum": 13.820592750000003},
{"lc": 505, "sum": 10.858824125000003},
],
},
{
"biobelt": 3,
"groups": [
{"lc": 101, "sum": 2.9620139375},
{"lc": 202, "sum": 386.50537182524516},
{"lc": 204, "sum": 8.520780075},
{"lc": 303, "sum": 2.963043},
{"lc": 401, "sum": 0.98779125},
{"lc": 402, "sum": 29.628224446078427},
{"lc": 403, "sum": 2.9654546875},
{"lc": 404, "sum": 3033.8446955982754},
{"lc": 405, "sum": 11.840650375000001},
{"lc": 406, "sum": 1.5623049637254902},
{"lc": 502, "sum": 0.9865655625},
{"lc": 504, "sum": 11.839350687500001},
{"lc": 505, "sum": 261.4439785000002},
],
},
{
"biobelt": 4,
"groups": [
{"lc": 101, "sum": 249.84825918750008},
{"lc": 1010, "sum": 68.128341125},
{"lc": 201, "sum": 0.9872954375},
{"lc": 202, "sum": 3094.1339089257276},
{"lc": 203, "sum": 0.98795175},
{"lc": 204, "sum": 113.20744741495099},
{"lc": 205, "sum": 8.8841160625},
{"lc": 301, "sum": 0.9873628125},
{"lc": 303, "sum": 25.668466125000002},
{"lc": 401, "sum": 2.962929875},
{"lc": 402, "sum": 342.8537512424021},
{"lc": 403, "sum": 2.9616924375},
{"lc": 404, "sum": 29452.056573613496},
{"lc": 405, "sum": 349.3813552247551},
{"lc": 406, "sum": 17.02855777132353},
{"lc": 408, "sum": 1.973944875},
{"lc": 501, "sum": 0.987261625},
{"lc": 502, "sum": 11.840911625},
{"lc": 504, "sum": 447.04775699999885},
{"lc": 505, "sum": 2654.865138601231},
{"lc": 510, "sum": 0.9859255},
{"lc": 601, "sum": 0.9870568125},
{"lc": 606, "sum": 16.7806923125},
{"lc": 808, "sum": 1.9739762500000002},
],
},
],
},
}
Loading

0 comments on commit aaf6ad0

Please sign in to comment.