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 8275391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:03:56+00:00 2026-06-08T08:03:56+00:00

Suppose there’s a sensor which records the date and time at every activation. I

  • 0

Suppose there’s a sensor which records the date and time at every activation. I have this data stored as a list in a .json file in the format (e.g.) “2000-01-01T00:30:15+00:00”.

Now, what I want to do is import this file in python and use NumPy/ Mathplotlib to plot how many times this sensor is activated per day.

My problem is, using this data, I don’t know how to write an algorithm which counts how many times the sensor is activated daily. (This should be simple, but due to limited Python knowledge, I’m stuck). Supposedly there is a way to split this list wrt T, bin each recording by date (e.g. “2000-01-01”) and then count the recordings on this date.

How would you count how many times the sensor is activated? (to then make a plot showing the number of activations each day?)

  • 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-06-08T08:04:01+00:00Added an answer on June 8, 2026 at 8:04 am

    First of all you need to load your JSON file:

    import json
    with open("logfile.json", "r") as logfile:
        records = json.load(logfile)
    

    Records will be a list or dictionary containing your records.

    Assuming that your logfile looks like:

    [u"2000-01-01T00:30:15+00:00",
     u"2000-01-01T00:30:16+00:00",
     ...
     ]
    

    Records will be a list of strings. So parsing the dates is just:

    import datetime
    for record in records:
        datepart, _ = record.split("T")
        date = datetime.datetime.strptime(datepart, "%Y-%m-%d")
    

    Hopefully that’s clear enough. Using “string”.split and datetime.strptime should do the trick, although you don’t have to parse this into a date object just to bin it but it may make things easier later on.

    Finally, binning should be pretty straightforward using a dictionary of lists. Starting
    from what we’ve got above let’s add binning:

    import collections
    import datetime
    date_bins = collections.defaultdict(list)
    for record in records:
        datepart, _ = record.split("T")
        date = datetime.datetime.strptime(datepart, "%Y-%m-%d")
        date_bins[date].append(record)
    

    This should give you a dictionary where each key is a date and each value is the list of records that were logged on that day.

    You’ll probably want to sort this by date (although you may be able to use collections.OrderedDict if the data is already in order).

    Counting activations per day could be something like:

    for date in date_bins:
        print "activations on %s: %s"%(date, len(date_bins[date]))
    

    Of course it’s a little bit more work to take that information and massage it into a format that matplotlib needs but it shouldn’t be too bad from here.

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

Sidebar

Related Questions

Suppose there is a System A which gives some output. This output is used
Suppose there is a table A which has a column AccessRights which is multivalued(
Suppose there exists a workflow service A. WF A may have more than a
Suppose there are 10 joins in a query and i want to find which
Suppose there are several boost strand share_ptr stored in a vector m_poStrands. And tJobType
Suppose there in an interface Displaceable and a class Circle which implements Displaceable. Displaceable
Suppose there is a site where we are uploading images. Now, when we have
Suppose there exists a function which returns a message say of the following format:
Suppose there is a list of ranges of numbers, for example, {0,9},{14,18},{19,30}. And I
Suppose there are n buttons and one datagridview. I drag a dataset which contains

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.