Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3755334
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:40:57+00:00 2026-05-19T09:40:57+00:00

I have a circulation pump that I check wither it’s on or off on

  • 0

I have a circulation pump that I check wither it’s on or off on and this is not by any fixed interval what so ever. For a single day that could give me a dataset looking like this where ‘value’ represents the pump being on or off.

data=(
 {'value': 0, 'time': datetime.datetime(2011, 1, 18, 7, 58, 25)},
 {'value': 1, 'time': datetime.datetime(2011, 1, 18, 8, 0, 3)},
 {'value': 0, 'time': datetime.datetime(2011, 1, 18, 8, 32, 10)},
 {'value': 0, 'time': datetime.datetime(2011, 1, 18, 9, 22, 7)},
 {'value': 1, 'time': datetime.datetime(2011, 1, 18, 9, 30, 58)},
 {'value': 1, 'time': datetime.datetime(2011, 1, 18, 12, 2, 23)},
 {'value': 0, 'time': datetime.datetime(2011, 1, 18, 15, 43, 11)},
 {'value': 1, 'time': datetime.datetime(2011, 1, 18, 20, 14, 55)})

The format is not that important and can be changed.

What I do want to know is how to calculate how many minutes ( or timespan or whatever) the 'value' has been 0 or 1 (or ON or OFF)?

This is just a small sample of the data, it stretches over several years so there could be a lot.
I have been using numpy/mathplotlib for plotting some graphs and there might be something in numpy to do this but I’m not good enough at it.

Edit

What I would like to see as an output to this would be a sum of the time in the different states. Something like…

0 04:42:13  
1 07:34:17
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T09:40:58+00:00Added an answer on May 19, 2026 at 9:40 am

    It really depends on how you’re going to treat this data points, are they representative of what? Generally, to know when switch occur you could use itertools.groupby like this:

    >>> from itertools import groupby
    >>> for i, grp in groupby(data, key=lambda x: x['value']):
        lst = [x['time'] for x in grp]
        print(i, max(lst) - min(lst))
    
    
    0 0:00:00
    1 0:00:00
    0 0:49:57
    1 2:31:25
    0 0:00:00
    1 0:00:00
    

    This is the example of minimal time you can be sure your system was up or down (assuming no interruptions between measurement).

    Once you decide how to treat your points, modification to this algorithm would be trivial.


    EDIT: since you only need sums of up/down-time, here is the simpler version:

    >>> sums = {0:datetime.timedelta(0), 1:datetime.timedelta(0)}
    >>> for cur, nex in zip(data, data[1:]):
        sums[cur['value']] += nex['time'] - cur['time']
    
    
    >>> for i, j in sums.items():
        print(i, j)
    
    
    0 5:32:10
    1 6:44:20
    

    If you expect long-periods of continuous up/down-time, you might still benefit of the itertools.groupby. This is py3k version, so it won’t be particularly efficient in py2k.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to find all patrons that have at least 1 circulation record. Here's
the question is : i have a table that contains details, this table is
I have a calculation that goes something like this: Price = value * randomNumberBetween(decimalValueA,
I have a small javascript pricing calculation that is not working on a friend's
I have a calculation that generates what appears to be the Float 22.23, and
I have some idea that it is due to some complex calculation, but i
I have a SQL statement (MS SQL Server 2005) that does a simple calculation
I have a method, which uses random samples to approximate a calculation. This method
I'm currently working on an assignment and this have had me stuck for hours.
I have a calculation application which I need to validate the fields to check

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.