From b2365cc318b674931b7826808ea50e064c4f01e5 Mon Sep 17 00:00:00 2001 From: David Brazda Date: Sat, 23 Sep 2023 06:48:20 +0200 Subject: [PATCH] gui - del arch runner for more ids be-support --- testy/isfalling.py | 46 ++++++++++ v2realbot/ENTRY_ClassicSL_v01.py | 79 ++++++++++++----- v2realbot/__pycache__/config.cpython-310.pyc | Bin 3345 -> 3403 bytes v2realbot/config.py | 5 +- v2realbot/controller/services.py | 32 ++++--- v2realbot/main.py | 6 +- v2realbot/static/js/archivetables.js | 12 ++- v2realbot/static/js/utils.js | 4 +- .../strategy/__pycache__/base.cpython-310.pyc | Bin 14770 -> 15207 bytes v2realbot/strategy/base.py | 22 +++-- .../utils/__pycache__/utils.cpython-310.pyc | Bin 16262 -> 18452 bytes v2realbot/utils/utils.py | 82 +++++++++++++++++- 12 files changed, 232 insertions(+), 56 deletions(-) create mode 100644 testy/isfalling.py diff --git a/testy/isfalling.py b/testy/isfalling.py new file mode 100644 index 0000000..db60a4e --- /dev/null +++ b/testy/isfalling.py @@ -0,0 +1,46 @@ +def isfalling_optimized(pole: list, pocet: int = None): + if pocet is None: pocet = len(pole) + if len(pole) j for i, j in zip(new_pole, new_pole[1:])) + return res + +def isfalling_optimizedgpt(pole: list, pocet: int = None): + if pocet is None: + pocet = len(pole) + if len(pole) < pocet: + return False + + # Prepare the list - all same consecutive values in the list are considered as one value. + new_pole = [pole[0]] + for i in range(1, len(pole)): + if pole[i] != pole[i - 1]: + new_pole.append(pole[i]) + + if len(new_pole) < pocet: + return False + + new_pole = new_pole[-pocet:] + print(new_pole) + + + # Perform the current calculation on this list. + res = all(i > j for i, j in zip(new_pole, new_pole[1:])) + return res + +pole = [8,2,8,1,4,4,4,3,3,3,2,1] +print(isfalling_optimizedgpt(pole,5)) \ No newline at end of file diff --git a/v2realbot/ENTRY_ClassicSL_v01.py b/v2realbot/ENTRY_ClassicSL_v01.py index 064fa13..8644b69 100644 --- a/v2realbot/ENTRY_ClassicSL_v01.py +++ b/v2realbot/ENTRY_ClassicSL_v01.py @@ -97,47 +97,85 @@ def next(data, state: StrategyState): ret = 0 state.ilog(lvl=1,e=f"Neexistuje indikator s nazvem {value} vracime 0" + str(e) + format_exc()) return ret - + + #OPTIMALIZOVANO CHATGPT #funkce vytvori podminky (bud pro AND/OR) z pracovniho dict def evaluate_directive_conditions(work_dict, cond_type): + def rev(kw, condition): + if directive.endswith(kw): + return not condition + else: + return condition + + cond = {} + cond[cond_type] = {} + + # Create a dictionary to map directives to functions + directive_functions = { + "above": lambda ind, val: get_source_or_MA(ind)[-1] > value_or_indicator(val), + "equals": lambda ind, val: get_source_or_MA(ind)[-1] == value_or_indicator(val), + "below": lambda ind, val: get_source_or_MA(ind)[-1] < value_or_indicator(val), + "falling": lambda ind, val: isfalling(get_source_or_MA(ind), val), + "rising": lambda ind, val: isrising(get_source_or_MA(ind), val), + "crossed_down": lambda ind, val: buy_if_crossed_down(ind, value_or_indicator(val)), + "crossed_up": lambda ind, val: buy_if_crossed_up(ind, value_or_indicator(val)), + "crossed": lambda ind, val: buy_if_crossed_down(ind, value_or_indicator(val)) or buy_if_crossed_up(ind, value_or_indicator(val)), + "pivot_a": lambda ind, val: is_pivot(source=get_source_or_MA(ind), leg_number=val, type="A"), + "pivot_v": lambda ind, val: is_pivot(source=get_source_or_MA(ind), leg_number=val, type="V"), + "still_for": lambda ind, val: is_still(get_source_or_MA(ind), val, 2), + } + + for indname, directive, value in work_dict[cond_type]: + for keyword, func in directive_functions.items(): + if directive.endswith(keyword): + cond[cond_type][directive + "_" + indname + "_" + str(value)] = rev("not_" + keyword, func(indname, value)) + + return eval_cond_dict(cond) + + #funkce vytvori podminky (bud pro AND/OR) z pracovniho dict + def evaluate_directive_conditions_old(work_dict, cond_type): + + #used for nots, reverse condition for not_ keywords + def rev(kw, condition): + if directive.endswith(kw): + return not condition + else: + return condition + cond = {} cond[cond_type] = {} for indname, directive, value in work_dict[cond_type]: #direktivy zobecnime ve tvaru prefix_ACTION # ACTIONS = is_above, is_below, is_falling, is_rising, crossed_up, crossed_down, is_pivot_a, is_pivot_v - + res = None #OBECNE DIREKTIVY - REUSOVATELNE if directive.endswith("above"): - cond[cond_type][directive+"_"+indname+"_"+str(value)] = get_source_or_MA(indname)[-1] > value_or_indicator(value) + #reverse if endswith "not_above" + res = rev("not_above", get_source_or_MA(indname)[-1] > value_or_indicator(value)) elif directive.endswith("equals"): - cond[cond_type][directive+"_"+indname+"_"+str(value)] = get_source_or_MA(indname)[-1] == value_or_indicator(value) + res = rev("not_equals",get_source_or_MA(indname)[-1] == value_or_indicator(value)) elif directive.endswith("below"): - cond[cond_type][directive+"_"+indname+"_"+str(value)] = get_source_or_MA(indname)[-1] < value_or_indicator(value) + res = rev("not_below", get_source_or_MA(indname)[-1] < value_or_indicator(value)) elif directive.endswith("falling"): - if directive.endswith("not_falling"): - cond[cond_type][directive+"_"+indname+"_"+str(value)] = not isfalling(get_source_or_MA(indname),value) - else: - cond[cond_type][directive+"_"+indname+"_"+str(value)] = isfalling(get_source_or_MA(indname),value) + res = rev("not_falling",isfalling(get_source_or_MA(indname),value)) elif directive.endswith("rising"): - if directive.endswith("not_rising"): - cond[cond_type][directive+"_"+indname+"_"+str(value)] = not isrising(get_source_or_MA(indname),value) - else: - cond[cond_type][directive+"_"+indname+"_"+str(value)] = isrising(get_source_or_MA(indname),value) + res = rev("not_rising", isrising(get_source_or_MA(indname),value)) elif directive.endswith("crossed_down"): - cond[cond_type][directive+"_"+indname+"_"+str(value)] = buy_if_crossed_down(indname, value_or_indicator(value)) + res = rev("not_crossed_down", buy_if_crossed_down(indname, value_or_indicator(value))) elif directive.endswith("crossed_up"): - cond[cond_type][directive+"_"+indname+"_"+str(value)] = buy_if_crossed_up(indname, value_or_indicator(value)) + res = rev("not_crossed_up", buy_if_crossed_up(indname, value_or_indicator(value))) #nefunguje moc dobre elif directive.endswith("crossed"): - cond[cond_type][directive+"_"+indname+"_"+str(value)] = buy_if_crossed_down(indname, value_or_indicator(value)) or buy_if_crossed_up(indname, value_or_indicator(value)) + res = rev("not_crossed", buy_if_crossed_down(indname, value_or_indicator(value)) or buy_if_crossed_up(indname, value_or_indicator(value))) elif directive.endswith("pivot_a"): - cond[cond_type][directive+"_"+indname+"_"+str(value)] = is_pivot(source=get_source_or_MA(indname), leg_number=value, type="A") + res = rev("not_pivot_a", is_pivot(source=get_source_or_MA(indname), leg_number=value, type="A")) elif directive.endswith("pivot_v"): - cond[cond_type][directive+"_"+indname+"_"+str(value)] = is_pivot(source=get_source_or_MA(indname), leg_number=value, type="V") + res = rev("not_pivot_v", is_pivot(source=get_source_or_MA(indname), leg_number=value, type="V")) elif directive.endswith("still_for"): #for 2 decimals - cond[cond_type][directive+"_"+indname+"_"+str(value)] = is_still(get_source_or_MA(indname),value, 2) - + res = rev("not_still_for", is_still(get_source_or_MA(indname),value, 2)) + if res is not None: + cond[cond_type][directive+"_"+indname+"_"+str(value)] = res #PRIPADNE DALSI SPECIFICKE ZDE # elif directive == "buy_if_necospecifckeho": # pass @@ -1728,6 +1766,7 @@ def next(data, state: StrategyState): res = state.buy(size=size) if isinstance(res, int) and res < 0: raise Exception(f"error in required operation LONG {res}") + #nastaveni SL az do notifikace, kdy je známá #pokud neni nastaveno SL v prescribe, tak nastavuji default dle stratvars if state.vars.activeTrade.stoploss_value is None: sl_defvalue = get_default_sl_value(direction=state.vars.activeTrade.direction) diff --git a/v2realbot/__pycache__/config.cpython-310.pyc b/v2realbot/__pycache__/config.cpython-310.pyc index 4ca0727458e903bcd219e3c0b8c6d6e85c04be7a..e87a26615f3e3141b0dd1a42ca51f22d07dd4fa4 100644 GIT binary patch delta 282 zcmYL?y-vbl6oz}gei2HjScL+GQUQM};NYe%8Y+^I(wJh*Sy)aPG~y*V*c)iNdkx0k zfr*p5UV@2N;fagy_B?r$C$T;({Xy3Y3hy)4qnAXtg#t-$`A9i5qY73vWu(w5m12cT zPXcR9Yh*APOm$k1RN9E-LQ7uASVdL< delta 228 zcmW-ay-vbV7>3VxdJ4T=P)Y&+DkR3i0GpEz&c=N6TVoh-AaP}|H_&wFCeCFT zCvS$)FTC6HV-o6TXQJXKvSqG)WS*b z;WRhz24^@g47U+-2Q7}!<}NzigW(uH_j6h%JV3-Lx;zv+LXF3Jdx0KbBIYZx*Ydp) zoAIrb`Unz9C6b!BjGi^!xwWT>=GB*ZrJ4IR3r&yCuT3>AtA`+^se22y}8L@(9u LXr#4Qr8fHqSF<%4 diff --git a/v2realbot/config.py b/v2realbot/config.py index fb4b7fc..e1a4780 100644 --- a/v2realbot/config.py +++ b/v2realbot/config.py @@ -35,7 +35,10 @@ COUNT_API_REQUESTS = False STRATVARS_UNCHANGEABLES = ['pendingbuys', 'blockbuy', 'jevylozeno', 'limitka'] DATA_DIR = user_data_dir("v2realbot") #BT DELAYS - +#profiling +PROFILING_NEXT_ENABLED = False +PROFILING_OUTPUT_DIR = DATA_DIR + """" LATENCY DELAYS for LIVE eastcoast .000 trigger - last_trade_time (.4246266) diff --git a/v2realbot/controller/services.py b/v2realbot/controller/services.py index ce8b087..6e65038 100644 --- a/v2realbot/controller/services.py +++ b/v2realbot/controller/services.py @@ -107,11 +107,11 @@ def modify_stratin(si: StrategyInstance, id: UUID): return (-1, "add data conf invalid") for i in db.stratins: if str(i.id) == str(id): - print("removing",i) + #print("removing",i) db.stratins.remove(i) - print("adding",si) + #print("adding",si) db.stratins.append(si) - print(db.stratins) + #print(db.stratins) db.save() return (0, i.id) return (-2, "not found") @@ -824,21 +824,25 @@ def edit_archived_runners(runner_id: UUID, archChange: RunArchiveChange): #delete runner in archive and archive detail and runner logs #predelano do JEDNE TRANSAKCE -def delete_archived_runners_byID(id: UUID): +def delete_archived_runners_byIDs(ids: list[UUID]): try: conn = pool.get_connection() - c = conn.cursor() - resh = c.execute(f"DELETE from runner_header WHERE runner_id='{str(id)}';") - print("header deleted",resh.rowcount) - resd = c.execute(f"DELETE from runner_detail WHERE runner_id='{str(id)}';") - print("detail deleted",resd.rowcount) - resl = c.execute(f"DELETE from runner_logs WHERE runner_id='{str(id)}';") - print("log deleted",resl.rowcount) - conn.commit() - print("commit") + out = [] + for id in ids: + c = conn.cursor() + print(str(id)) + resh = c.execute(f"DELETE from runner_header WHERE runner_id='{str(id)}';") + print("header deleted",resh.rowcount) + resd = c.execute(f"DELETE from runner_detail WHERE runner_id='{str(id)}';") + print("detail deleted",resd.rowcount) + resl = c.execute(f"DELETE from runner_logs WHERE runner_id='{str(id)}';") + print("log deleted",resl.rowcount) + out.append(str(id) + ": " + str(resh.rowcount) + " " + str(resd.rowcount) + " " + str(resl.rowcount)) + conn.commit() + print("commit") # if resh.rowcount == 0 or resd.rowcount == 0: # return -1, "not found "+str(resh.rowcount) + " " + str(resd.rowcount) + " " + str(resl.rowcount) - return 0, str(resh.rowcount) + " " + str(resd.rowcount) + " " + str(resl.rowcount) + return 0, out except Exception as e: conn.rollback() diff --git a/v2realbot/main.py b/v2realbot/main.py index fa8108e..c2420ca 100644 --- a/v2realbot/main.py +++ b/v2realbot/main.py @@ -319,9 +319,9 @@ def _get_all_archived_runners() -> list[RunArchive]: raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"No data found") #delete archive runner from header and detail -@app.delete("/archived_runners/{runner_id}", dependencies=[Depends(api_key_auth)], status_code=status.HTTP_200_OK) -def _delete_archived_runners_byID(runner_id): - res, id = cs.delete_archived_runners_byID(id=runner_id) +@app.delete("/archived_runners/", dependencies=[Depends(api_key_auth)], status_code=status.HTTP_200_OK) +def _delete_archived_runners_byIDs(runner_ids: list[UUID]): + res, id = cs.delete_archived_runners_byIDs(ids=runner_ids) if res == 0: return id elif res < 0: raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Error: {res}:{id}") diff --git a/v2realbot/static/js/archivetables.js b/v2realbot/static/js/archivetables.js index f2242f2..205423a 100644 --- a/v2realbot/static/js/archivetables.js +++ b/v2realbot/static/js/archivetables.js @@ -129,7 +129,7 @@ $(document).ready(function () { // Loop through the selected rows and display an alert with each row's ID rows.every(function (rowIdx, tableLoop, rowLoop ) { var data = this.data() - ids_to_del = ids_to_del + data.id + "
" + ids_to_del = ids_to_del + data.id + "
" }); $('#listofids').html(ids_to_del); @@ -342,19 +342,21 @@ $("#editModalArchive").on('submit','#editFormArchive', function(event){ }) }); -function delete_arch_row(id) { +function delete_arch_rows(ids) { $.ajax({ - url:"/archived_runners/"+id, + url:"/archived_runners/", beforeSend: function (xhr) { xhr.setRequestHeader('X-API-Key', API_KEY); }, method:"DELETE", contentType: "application/json", dataType: "json", + data: JSON.stringify(ids), success:function(data){ $('#delFormArchive')[0].reset(); window.$('#delModalArchive').modal('hide'); $('#deletearchive').attr('disabled', false); + console.log(data) archiveRecords.ajax.reload(); }, error: function(xhr, status, error) { @@ -373,11 +375,13 @@ $("#delModalArchive").on('submit','#delFormArchive', function(event){ $('#deletearchive').attr('disabled','disabled'); //rows = archiveRecords.rows('.selected'); if(rows.data().length > 0 ) { + runnerIds = [] // Loop through the selected rows and display an alert with each row's ID rows.every(function (rowIdx, tableLoop, rowLoop ) { var data = this.data() - delete_arch_row(data.id) + runnerIds.push(data.id); }); + delete_arch_rows(runnerIds) } }); diff --git a/v2realbot/static/js/utils.js b/v2realbot/static/js/utils.js index 84f94df..0d48ece 100644 --- a/v2realbot/static/js/utils.js +++ b/v2realbot/static/js/utils.js @@ -3,8 +3,8 @@ API_KEY = localStorage.getItem("api-key") var chart = null // var colors = ["#8B1874","#B71375","#B46060","#61c740","#BE6DB7","#898121","#4389d9","#00425A","#B5D5C5","#e61957","#8B1874","#B71375","#B46060","#61c740","#BE6DB7","#898121","#4389d9","#00425A","#B5D5C5","#e61957"] // var reset_colors = ["#8B1874","#B71375","#B46060","#61c740","#BE6DB7","#898121","#4389d9","#00425A","#B5D5C5","#e61957","#8B1874","#B71375","#B46060","#61c740","#BE6DB7","#898121","#4389d9","#00425A","#B5D5C5","#e61957"] -var colors = ["#8B1874","#B71375","#B46060","#61c740","#BE6DB7","#898121","#4389d9","#00425A","#B5D5C5","#e61957","#7B0E60","#550844","#9B2888","#BD38A0","#A30F68","#6E0B50","#CA2183","#E6319B","#A04C54","#643848","#CA7474","#E68D8D","#4F9C34","#3B7128","#73DF4D","#95EF65","#A857A4","#824690","#D087CC","#E2A1DF","#79711B","#635D17","#99912B","#B1A73D","#3779C9","#2B68B3","#5599ED","#77A9F7","#003A4C","#002F3B","#004C67","#00687D","#A1C6B5","#8CC6A5","#C9E6D5","#E4F6EA","#D2144A","#A60F3B","#FA2463","#FF3775"]; -var reset_colors = ["#8B1874","#B71375","#B46060","#61c740","#BE6DB7","#898121","#4389d9","#00425A","#B5D5C5","#e61957","#7B0E60","#550844","#9B2888","#BD38A0","#A30F68","#6E0B50","#CA2183","#E6319B","#A04C54","#643848","#CA7474","#E68D8D","#4F9C34","#3B7128","#73DF4D","#95EF65","#A857A4","#824690","#D087CC","#E2A1DF","#79711B","#635D17","#99912B","#B1A73D","#3779C9","#2B68B3","#5599ED","#77A9F7","#003A4C","#002F3B","#004C67","#00687D","#A1C6B5","#8CC6A5","#C9E6D5","#E4F6EA","#D2144A","#A60F3B","#FA2463","#FF3775"]; +var colors = ["#8B1874","#B71375","#B46060","#61c740","#BE6DB7","#898121","#4389d9","#00425A","#B5D5C5","#e61957","#7B0E60","#9B2888","#BD38A0","#A30F68","#6E0B50","#CA2183","#E6319B","#A04C54","#643848","#CA7474","#E68D8D","#4F9C34","#3B7128","#73DF4D","#95EF65","#A857A4","#824690","#D087CC","#E2A1DF","#79711B","#635D17","#99912B","#B1A73D","#3779C9","#2B68B3","#5599ED","#77A9F7","#003A4C","#002F3B","#004C67","#00687D","#A1C6B5","#8CC6A5","#C9E6D5","#E4F6EA","#D2144A","#A60F3B","#FA2463","#FF3775"]; +var reset_colors = ["#8B1874","#B71375","#B46060","#61c740","#BE6DB7","#898121","#4389d9","#00425A","#B5D5C5","#e61957","#7B0E60","#9B2888","#BD38A0","#A30F68","#6E0B50","#CA2183","#E6319B","#A04C54","#643848","#CA7474","#E68D8D","#4F9C34","#3B7128","#73DF4D","#95EF65","#A857A4","#824690","#D087CC","#E2A1DF","#79711B","#635D17","#99912B","#B1A73D","#3779C9","#2B68B3","#5599ED","#77A9F7","#003A4C","#002F3B","#004C67","#00687D","#A1C6B5","#8CC6A5","#C9E6D5","#E4F6EA","#D2144A","#A60F3B","#FA2463","#FF3775"]; var indList = [] diff --git a/v2realbot/strategy/__pycache__/base.cpython-310.pyc b/v2realbot/strategy/__pycache__/base.cpython-310.pyc index 563966a8c64592068ece2da27d19cadc821425f8..c6f382eb2710e8b60b57140f20fd60ce0efb0920 100644 GIT binary patch delta 4931 zcmb7IYit}>6`s4hUhn$tJnYzB$FHoDX|m44c{pj>tP{Jb!Ld`vA;}QBY<9-U#xpzH zJF|8YIV_O0r9y4eUf@SnsZMEuh>EH;&{nNlA;F&(D6c{~Ezt5Tf)D9);Pd!)@V-GyI_P(OkqP18tEyfg` z=@GM4Yo+g~xzcLW+N^f1-RjUfq^!d1w7Rq|NmrVythg4Jbd}j{t=3jcy4qZ0shTS3 z8uKP=t+rOuwdOi2p(P|;XZBd@we^y&H;WsrjoL;zSYmFndbM6jFD0eT+GcBuwndJY znOm)G+BU0C>yzV%xn0{%hAuaEST}1oOJ0My(~4-fFvV!$&yuXsyw%#J?V|CnbBdPS ztLQ8Art^y4bS|Lv)2LZ*Ij>adEi~M%M-C`zOw6)3SwzePj`nyB`^QFa8yX%O*_#>} zJUpHn9O>UZJUHMjEAdAUj_*G>o*Eb$o4XR|WmPKkBKx^Lku?oIR~bqK`+CXWd=r7n zIA}HQMeQkr^Q>+-d_ANa02={Pc{8XUkuTRbZ2`HJz>B0Dmm6uzk!$fK-~}g*(_T4u z?bHUHBT#F+kYkt=;=ahHrIItRMzYHaKOkO?WGXvp;Or&{2gJr` zt4KyeVkEkoCB=i$r-r13`$)=@fWrU{@NvLVz$XAl2-K*rGysOwYyve37!vnYbdQXI zluIT-Ngd3*(UM-+KQcc61qtIsd6BfPr}VU&9u@zt*vxL5+f?}^E8aq)Gv$X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teD(-yp3k;`q+JS)4Xr#{Y=9?*l#{ za0?R&%}OQ`tLhKM>xHio6bhBM0R9AkL%lM_(yO-1`Fw!{bMQF~5Bq{_G~6&4;b6yi z^Up-vt`FE9qOiZExCTqeubNt+_E(GX{u)+CR2QokPxN=N2Jz$m&8$&;Oq?cBF%W0X zVsN02#l-P}jr4Jx9cak5VvRPydIEZ#o~JKwEtQ`0`pia1ehNu&aWSQ>^c|i`&MV;z zPo*7t2j{42Y2VGxJEz!~fU)KAr-Tz; diff --git a/v2realbot/strategy/base.py b/v2realbot/strategy/base.py index 3106e0d..e0ac7d1 100644 --- a/v2realbot/strategy/base.py +++ b/v2realbot/strategy/base.py @@ -6,7 +6,7 @@ from v2realbot.utils.utils import AttributeDict, zoneNY, is_open_rush, is_close_ from v2realbot.utils.tlog import tlog from v2realbot.utils.ilog import insert_log, insert_log_multiple_queue from v2realbot.enums.enums import RecordType, StartBarAlign, Mode, Order, Account -from v2realbot.config import BT_DELAYS, get_key, HEARTBEAT_TIMEOUT, QUIET_MODE, LOG_RUNNER_EVENTS, ILOG_SAVE_LEVEL_FROM +from v2realbot.config import BT_DELAYS, get_key, HEARTBEAT_TIMEOUT, QUIET_MODE, LOG_RUNNER_EVENTS, ILOG_SAVE_LEVEL_FROM,PROFILING_NEXT_ENABLED, PROFILING_OUTPUT_DIR import queue #from rich import print from v2realbot.loader.aggregator import TradeAggregator2Queue, TradeAggregator2List, TradeAggregator @@ -25,9 +25,10 @@ from threading import Event, current_thread import json from uuid import UUID from rich import print as printnow -#from pyinstrument import Profiler +if PROFILING_NEXT_ENABLED: + from pyinstrument import Profiler + profiler = Profiler() -#profiler = Profiler() # obecna Parent strategie podporující queues class Strategy: def __init__(self, name: str, symbol: str, next: callable, init: callable, account: Account, mode: str = Mode.PAPER, stratvars: AttributeDict = None, open_rush: int = 30, close_rush: int = 30, pe: Event = None, se: Event = None, runner_id: UUID = None, ilog_save: bool = False) -> None: @@ -328,9 +329,11 @@ class Strategy: #self.state.ilog(e="Rush hour - skipping") else: # Profile the function - #profiler.start() + if PROFILING_NEXT_ENABLED: + profiler.start() self.next(item, self.state) - #profiler.stop() + if PROFILING_NEXT_ENABLED: + profiler.stop() self.after_iteration(item) ##run strategy live @@ -393,10 +396,11 @@ class Strategy: tlog(f"FINISHED") print(40*"*",self.mode, "STRATEGY ", self.name,"STOPPING",40*"*") - # now = datetime.now() - # results_file = "profiler"+now.strftime("%Y-%m-%d_%H-%M-%S")+".html" - # with open(results_file, "w", encoding="utf-8") as f_html: - # f_html.write(profiler.output_html()) + if PROFILING_NEXT_ENABLED: + now = datetime.now() + results_file = PROFILING_OUTPUT_DIR + "/"+"profiler"+now.strftime("%Y-%m-%d_%H-%M-%S")+".html" + with open(results_file, "w", encoding="utf-8") as f_html: + f_html.write(profiler.output_html()) self.stop() diff --git a/v2realbot/utils/__pycache__/utils.cpython-310.pyc b/v2realbot/utils/__pycache__/utils.cpython-310.pyc index fd83525c5782591253b0816b9c1b121d244b8609..137554b2bd5958798759ab63127faf36bb49f743 100644 GIT binary patch delta 3974 zcmbtW3v5%@8NTQG+PQHY$AsWGLe6OPR* zbryzGU|ZJ}4wXtbL_*t1VHH|Q#kMlCX{%PYR_f@qA(;+Vs!o+qyRFe4FhTeK*9s&B z)N0r|-#O>|pZCA#o^$pO9(k5ods9=*68^GprfN^GJ7mpa$=()CiAmnont9j+OGlV@ z4Lkx(Xk&pPDAhbLOIr*JG*71qmcxo6qxWlf@n3~UkzWgsq4ol8ai;<+VHL({Mf*Vy zhHZuxoVGy>R>PVh=3NI*!CK7-t-5j>tV8p!!+xDxkKr~TZ-R~BMSlHV{Nu0*`3=*2 zY=$k!ZNvyZZ5c*<0{l4lLTnJ)wL0j~0|97AK8{LvxK8LoZqqbwD+G|+JdN81-N)wt+mj{Op|!(KtpUr^j!(7= zcB6R*?7`F$Y#p-w@FcPTQ5Zls8hir=vF`-ARdO8|8#ioq3>xUgV|xT!_$7ph1PtUM zDZ;>@_cADYZ`h`QQ6Cw>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yfh&rG>P-c2 z6g%y9BK4_C0Qn~meyQanPTR@wF*cTDCEg~pJBOLbFe^qdgS@Taj*@cM9*+8yz^O)| zL4Lu@r!GTGL@o~bdp#`E2jrcu`&BsN9u(i@j1Go3Sj8aUXL~opCj`478t3);gT8Q> zF1fDEH%!mSLNT)cv?rP+M>LjRgl0d*vS!rwU#?#Z1|R0@BKKHCSK9~ikAFN}J5z~7wp53`1l))IxKQD}_9lBd2{Zl;I<=o16;qNvSY!OxGJ1B8x`E#4Kw|l`R9{k$#CLJ);;)$D{(_>@hxAi$}+#s<#yUZOo{| zvD`NgMgmyr*9=CGHo)BE6r5C+Y&8!L!V1!kJIivi`3gJLuG@Hq zZQ-#rh375w`5OmmOCypJ6uAfQmbp#4*zClj@>~&4hA)UB+wiR%M5l7W1#-qD~5xDUsj~Iu4e`r_%ZaTix$h1ylP$`Ee#uiK4tor>nC92?XWY@Fkn+ j for i, j in zip(pole, pole[1:])) return res +#optimized by gpt and same values are considered as one +def isfalling(pole: list, pocet: int = None): + if pocet is None: + pocet = len(pole) + if len(pole) < pocet: + return False + + # Prepare the list - all same consecutive values in the list are considered as one value. + new_pole = [pole[0]] + for i in range(1, len(pole)): + if pole[i] != pole[i - 1]: + new_pole.append(pole[i]) + + if len(new_pole) < pocet: + return False + + new_pole = new_pole[-pocet:] + #print(new_pole) + + + # Perform the current calculation on this list. + res = all(i > j for i, j in zip(new_pole, new_pole[1:])) + return res + #vraci zda dane pole je roustouci (bud cele a nebo jen pocet poslednich) -def isrising(pole: list, pocet: int = None): +def isrising_old(pole: list, pocet: int = None): if pocet is None: pocet = len(pole) if len(pole)