#🔒 how to solve this specific problem

125 messages · Page 1 of 1 (latest)

icy wasp
#

i have this issue where i cant think of way to find what causing the missbehavior, its about the states.increment(line 39) it should do the following

formated   - literal
00:00:000  - 0.0

command increment

00:01:000  - 1.0

command change_target to 0
command increment

01:01:000  - 61.0

but for some reason it didnt do that(with more actions involved)

here is my pastebin
https://paste.pythondiscord.com/RYKQ

loud egretBOT
#

@icy wasp

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

shell cedar
#

what output do you get then

icy wasp
#

juct comment out the missing lib

shell cedar
#

just paste the output please, I'm not going to run your code here

icy wasp
#

okay then

icy wasp
shell cedar
#

well how is it misbehaving?

icy wasp
#
hitoya@hitoya-travelmate5730:~$ python ~/Downloads/programs/tools_cripts/clicker/clicker.py
Node - Timing
03 - 00:04:000
00 - 00:01:000
01 - 00:02:000
['dec']
^CTraceback (most recent call last):
  File "/home/hitoya/Downloads/programs/tools_cripts/clicker/clicker.py", line 145, in <module>
    main()
  File "/home/hitoya/Downloads/programs/tools_cripts/clicker/clicker.py", line 143, in main
    screen.join()
  File "/usr/lib/python3.12/threading.py", line 1147, in join
    self._wait_for_tstate_lock()
  File "/usr/lib/python3.12/threading.py", line 1167, in _wait_for_tstate_lock

shell cedar
#

what is the expected behavior then?

icy wasp
shell cedar
#

where do you see 59:59:999

icy wasp
#

it should give 00:00:000 to 59:00:00 instead

shell cedar
#

I only see 00:04:000, 00:01:000 and 00:02:000, nothing like what you describe

icy wasp
shell cedar
#

I don't understand. Do you mean that instead of those 3 lines it should print only 00:00:000 and 59:00:00?

icy wasp
#

the output was actualy cleared before writing next step

icy wasp
#

the one on middle is the one supposed change

#

i dont have proper closing currently so i do interrupt

shell cedar
#

I don't really understand what this script is even supposed to do

#

it looks like you have two threads here, why?

icy wasp
#

just look on the line 39

#

the states.increment

#

thats the thing i want to know how i messed up

shell cedar
#

and they access shared structures but without any kind of synchronization

icy wasp
#

not sure what that supposed to do or mean

shell cedar
#

well what is that method supposed to do in the first place?

icy wasp
shell cedar
#

from the looks of it the logic is a tad more complicated than that

icy wasp
#

so like

minuites:second:millisec

#

it will point wich of those 3 then increment

#

but i represent the data as float

icy wasp
shell cedar
#

so states.data is a list of seconds?

icy wasp
#

yes

#

millisec actualy

shell cedar
#

I thought they were floats

icy wasp
#

its float yes

#

eh im loosing my language sorry

shell cedar
#

but if the unit of each element is millisecond then you would only need floats for sub-millisecond accuracy

icy wasp
#

the accuracy i currently need is upto 0.001

#

its realy easy to increase accuracy

shell cedar
#

so the increment static method is used to increment the selected time (determined by pointer), and the field (minute, second, millisecond) is determined by target?

#

I would advise to simplify the logic of ru() until you get the increment logic right

icy wasp
#

yes

icy wasp
#

I'll build the input logic later

shell cedar
#

but this way of testing involves random numbers which makes this more difficult – at least set a constant random seed for reproducible results

icy wasp
#

random increments/decrements

shell cedar
#

yes

icy wasp
#

it only Dec or inc ones

shell cedar
#

it also randomly changes the field to change

#

so, let's go over the logic of increment

#

the number of seconds to add or subtract is basically determined by cls.target, yes?

icy wasp
#

yes

#

it will tell if it will increment by minutes, seconds or millisecond

#

I don't have good name for the states. target

#

forgive me for that one

shell cedar
#

I just don't understand why the code is so complex. Isn't the only thing you need to do just:

increment = (60, 1, 0.001)[cls.target]
if not inc:
    increment = -increment

cls.data[cls.pointer] += increment
#

or am I missing something?

icy wasp
#

I hope that helps

shell cedar
#

yes, isn't my code doing exactly that?

icy wasp
#

the one you show it does

#

but the one I have didn't

shell cedar
#

what was your logic there then

icy wasp
#

basically it mods the target value to it's base

#

the base arrangements is
60,60,1000

#

it will make decrements put it to the previous value and if it's 0 it will give base-1

shell cedar
#

why is that necessary when you can just increment the target value?

#

you only need to break down the value into parts for display purposes

icy wasp
shell cedar
#

only if the value drops below zero

#

if the target value is 61 and you decrement, then obviously it will be 1 afterwards

#

what part of this is unexpected or unwanted?

icy wasp
#

?

shell cedar
#

is there a deeper logic here that you haven't explained yet?

icy wasp
#

I can put a comment on each line....

shell cedar
#

they're not helpful to me

icy wasp
#

let me try to explain how the logic works

shell cedar
#

maybe this is what you meant: if the value is 0:05:40 and target = 0 and you decrement, you want nothing to change?

icy wasp
#

i dont understand why its not behaving well but what i wanna hapen there is the value will be 59:05:400

shell cedar
#

please answer my question

icy wasp
#

the question is bit vague

shell cedar
#

no, it's not

#

what is the expected end result in that case?

icy wasp
#

what "nothing" is talking to?

shell cedar
#

that the value remains unchanged

icy wasp
shell cedar
#

I see, so it basically rolls over

icy wasp
#

thats why "mod"

#

like a clock

#

if you ever had a quartz clock

#

the way you set its digital time

#

tho you only incement there

shell cedar
#

ok, next question: if the value is 01:40:59 and target=2 and you increment, what is the end result?

icy wasp
#

01:40:591

shell cedar
#

my bad, let me try again

icy wasp
#

0 = minuites
1 = seconds
2 = millisec

shell cedar
#

so target=1, value is 01:59:000

icy wasp
#

the literal value will be 120.0 thus the formated will be 02:00:000

#

the display will only know what the literal value is

#

honestly my brain is currently heating up

shell cedar
#

ok so the valid values range from 0 to 3599.999?

#

the latter being 59:59.999

icy wasp
shell cedar
#

I only asked about the valid value range

icy wasp
#

and if its all zero thenyou decrement while at target = 0 it should go 59:59:999

shell cedar
#

to make sure we're on the same page

icy wasp
#

range is 0..60*60-0.001

shell cedar
#

that's 35.999

#

maybe it would be easier to store the individual fields separately?

icy wasp
#

the source of those timing are from time.time

icy wasp
#

i can just make classmethod that will add new node

#

hmmmmm

#

idk

#

thanks for the time

#

it really appreciated

loud egretBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.