0

final format for E-Ink Python
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

final format for E-Ink Python

by scotch1 on Sat Feb 27, 2021 2:36 am

Can anyone help with final formatting of a time delta result to only minutes as a number for a countdown:
equation is:
Code: Select all | TOGGLE FULL SIZE
differential = next_class_start - time_now


Call of:
Code: Select all | TOGGLE FULL SIZE
print(*differential)

Result:
Code: Select all | TOGGLE FULL SIZE
0 days 00:04:32.133860


Seeking to have ONLY minutes, convertible to a number for operations, conditional statements
.

Reference isn't clear enough: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Timedelta.html

Used without the *:
Code: Select all | TOGGLE FULL SIZE
print(differential)

Results in:
Code: Select all | TOGGLE FULL SIZE
66   00:00:21.336076
Name: START, dtype: timedelta64[ns]

scotch1
 
Posts: 214
Joined: Mon Nov 26, 2012 12:13 am

Re: final format for E-Ink Python

by millercommamatt on Mon Mar 01, 2021 3:18 pm

timedeltas are stored as days, seconds, and microseconds https://docs.python.org/3/library/datetime.html#timedelta-objects

If you want only minutes you could do this:
Code: Select all | TOGGLE FULL SIZE
import datetime as dt
test_diff = dt.timedelta(days=2, hours=3, seconds=4.5)
mins = (test_diff.days*60*60*24 + test_diff.seconds)/60  # ignoring the microseconds
print(mins)
print('{:.2f} minutes elapsed'.format(mins))


round or floor or string format as you would like to present the minutes the way you want

millercommamatt
 
Posts: 653
Joined: Tue Jul 31, 2018 4:57 pm

Re: final format for E-Ink Python

by scotch1 on Tue Mar 02, 2021 2:45 am

OK, might have lucked out in approach of attached code, which effectively works on laptop, then breaks in PI/E-ink and I can't understand it.... see how the conditional statement works when minutes to next class are within the target, then, somehow, when it goes to zero, totally goes blank for the first minute...... Laptop python prep below and attached, PI in next post... Really would appreciate help to finish before my kids go back to school in 2 weeks ;( (plus, intend on conditional statement is to sound a buzzer when minutes_next gets to 1 min, think I have that sorted, if I can get the code to work in PI/e-ink......

Code in Python on Laptop:
A_WIP_006.py
(3.11 KiB) Downloaded 4 times

references this file:
class_shedule_2.csv
(1.71 KiB) Downloaded 2 times

image:
Skool_PI_Timedelta_1.JPG
Skool_PI_Timedelta_1.JPG (47 KiB) Viewed 141 times


Result:
Code: Select all | TOGGLE FULL SIZE
Info:
22:22 PM
Mon
Monday
Schoolday
load school schedule
Into Bed, Story time
Next Event is: Dream Land
Next event is a class, starting at:  22:26PM
219.83
[b]3.66[/b]
Class Starting in: [b]3.66[/b] minutes


Gets to less than 0 min and goes blank:
Code: Select all | TOGGLE FULL SIZE
Info:
22:26 PM
Mon
Monday
Schoolday
load school schedule

Next Event is:
Not a next class


then after the minute is passed, starts reading the info again:
Code: Select all | TOGGLE FULL SIZE
Info:
22:28 PM
Mon
Monday
Schoolday
load school schedule
Dream Land
Next Event is: Sleeping Right
Not a next class


Now SAME code in Raspberry Pi and the Pimorini inky pHAT:
Error: Next post.....

scotch1
 
Posts: 214
Joined: Mon Nov 26, 2012 12:13 am

Re: final format for E-Ink Python

by scotch1 on Tue Mar 02, 2021 2:56 am

This is the pi to inky/phat code which seems to:
1) work when next_class_status = 'No', displays "N/a"s
2) breaks at lines 81 when 'Yes'
Skool_PI_Timedelta_2.JPG
Skool_PI_Timedelta_2.JPG (115.02 KiB) Viewed 141 times


NOte, I had to change lines 131 and 134 to str(*message.EVENT) and str(*message_ahead) to work but then it breaks.
skool_3_WIP.py
(4.73 KiB) Downloaded 2 times


Easiest way to test it is to open the csv file, change start of next class and add a "Yes" if not obvious.

Any way to get it running would be extremely appreciated :)

scotch1
 
Posts: 214
Joined: Mon Nov 26, 2012 12:13 am

Re: final format for E-Ink Python

by millercommamatt on Tue Mar 02, 2021 10:24 am

A few things I see from a cursory glance at your code:

Redundant import statements:
Code: Select all | TOGGLE FULL SIZE
import datetime
from datetime import timedelta


if you want to keep commands smaller try:
Code: Select all | TOGGLE FULL SIZE
from datetime import datetime
from datetime import timedelta


Now you can use datetime instead of datetime.datetime


Doublecheck your datatypes.
The error on line 81 in complaining that one variable is a string and one is a datetime. Both need to be types supported by datetime.


Keep experimenting. If I have time later, I'll take a deeper look and try to piece together what you're doing and where things are going awry.

millercommamatt
 
Posts: 653
Joined: Tue Jul 31, 2018 4:57 pm

Re: final format for E-Ink Python

by millercommamatt on Tue Mar 02, 2021 1:23 pm

You're getting a blank because your time_now_str is greater or equal to the end or less than or equal to the next start.

Use >= and <= instead of > and <. Or, adjust your Start and End time to not have a gap at minute resolution.

millercommamatt
 
Posts: 653
Joined: Tue Jul 31, 2018 4:57 pm

Re: final format for E-Ink Python

by scotch1 on Wed Mar 03, 2021 3:29 am

Appreciate the insight: See the bracket issue and complication on seeing two values.

Believe the >= solved the laptop version.

The PI version still having an issue with the line 81 equation which works on laptop, wondering if it was teh default "n/a" values as strings or str in the eink display sections, shown here:
1:
pi_eink_line81.JPG
pi_eink_line81.JPG (128.36 KiB) Viewed 115 times

2:
pi_eink_line111.JPG
pi_eink_line111.JPG (109.11 KiB) Viewed 115 times

3:
pi_eink_line131.JPG
pi_eink_line131.JPG (112.79 KiB) Viewed 115 times

scotch1
 
Posts: 214
Joined: Mon Nov 26, 2012 12:13 am

Re: final format for E-Ink Python

by scotch1 on Wed Mar 03, 2021 3:36 am

...Also, I decided to buy an M4 + ThinkInk 2.9" + realtime clock to get around the slowness of the Pimorini EInk refresh (15 sec) and slow debugging thru VNC thinking that circuit python on the M4 would be the answer to more reliable python usage: However as seen in this post https://forums.adafruit.com/viewtopic.php?f=60&t=176221, it appears that the M4 can't read csv or use pandas. Had the script set up using about 200 lines of conditional statements for day and time, then friend suggested using pandas to read the timetable which pushed my coding to get to this point and get the values, but see that it'll be no use to the M4?

Do you think M4 can work with this python code set up for pi? Can the Think Ink 2.9" feather be used with the PI if I have to sub off and hardwire the pi to it?

scotch1
 
Posts: 214
Joined: Mon Nov 26, 2012 12:13 am

Re: final format for E-Ink Python

by scotch1 on Fri Mar 05, 2021 4:16 am

Found it: Seems the variable was being defined as a N/A string and caused the issue!
founderror.JPG
founderror.JPG (98.96 KiB) Viewed 92 times

THat plus some last item strftime, and it goes!
Whoo!

scotch1
 
Posts: 214
Joined: Mon Nov 26, 2012 12:13 am

Re: final format for E-Ink Python

by millercommamatt on Fri Mar 05, 2021 10:27 am

huzzah!

millercommamatt
 
Posts: 653
Joined: Tue Jul 31, 2018 4:57 pm

Please be positive and constructive with your questions and comments.