#๐Ÿ”’ How to get the time spent on an app thanks to log info

14 messages ยท Page 1 of 1 (latest)

radiant lake
#

Hello, I have to know how much time did someone spent time on an app, but I have no idea how to do it. Basicallt what I did till now is that I created a list out of the login/logout infos that look like this:

['2021-11-22 13:22:10;Adam;login', '2021-11-22 13:23:11;Kacper;login', '2021-11-22 13:25:21;Adam;logout', '2021-11-22 14:00:32;Kacper;logout', '2021-11-23 14:42:44;Adam;login', '2021-11-23 15:11:59;Kacper;login', '2021-11-23 15:30:00;Adam;logout', '2021-11-23 15:49:21;Kacper;logout', '']
``` it contains the time, login or logout and the name. The thing is that I don't know what to do in order to compute the time spent on it. Like I was thinking about making it into dictionaries, but I am not sure if this is the right way to do it. I am not asking about help with coding, but with what I should code. I am not ure if I explained well what I need, so if you need any more specifications just ask.
strong sailBOT
#

@radiant lake

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.

thick blade
#

Well, the right way would be in a database

#

and having the time saved somewhere to avoid iterate thru that list

radiant lake
# thick blade Well, the right way would be in a database

I mean it is just to learn, there isn't an actual app. the logs appear like that in a text file:

2021-11-22 13:23:11;Kacper;login
2021-11-22 13:25:21;Adam;logout
2021-11-22 14:00:32;Kacper;logout
2021-11-23 14:42:44;Adam;login
2021-11-23 15:11:59;Kacper;login
2021-11-23 15:30:00;Adam;logout
2021-11-23 15:49:21;Kacper;logout
``` it's like just a practice exercise
thick blade
#

Ok, but what do you want to practice? xD

radiant lake
# thick blade Ok, but what do you want to practice? xD

I need to calculate the user's time spent on the "app" using this:

2021-11-22 13:23:11;Kacper;login
2021-11-22 13:25:21;Adam;logout
2021-11-22 14:00:32;Kacper;logout
2021-11-23 14:42:44;Adam;login
2021-11-23 15:11:59;Kacper;login
2021-11-23 15:30:00;Adam;logout
2021-11-23 15:49:21;Kacper;logout```
I am quite a beginner, and I don't know how to do it.
thick blade
#

Well, you can use datetime with that timestamp

#

and make the diff

radiant lake
#

and do it directly from the text file, so it remains a single string?

thick blade
#

I mean, you have to use split, and you have string[0] as timestamp, string[1] as name...

radiant lake
#

So I still convert it to a list, ok.

strong sailBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.