1
0
Fork 0
Browse Source

Squashed commit of the following:

commit 3c15bf541e
Author: Craig Oates <craig@craigoates.net>
Date:   Sun May 9 00:26:07 2021 +0100

    change save_filtered_flickers to use writerow.

    It was using writewrows before this but writerow makes it easier to
    change. This is probably a nothing change but hey-ho!

commit c73f5b2d25
Author: Craig Oates <craig@craigoates.net>
Date:   Sun May 9 00:19:07 2021 +0100

    add fix to stop duplicating entries in find_readings_with_lights_on.

    The function was originally looping through the set of readings for a
    particular time-stamp. If there was more than one reading above 39, it
    would append that particular time-stamp every time the if-statement
    was true -- as it looped through each reading for said time-stamp.

    This change adds a break and a variable to track if the time-stamp
    should be added to the list -- after it has broke out of the
    if-block.

commit f35fdd611a
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 21:27:54 2021 +0100

    add comments to flicker.py explaining process.

    These comments explain how each 'section' works with the data. There
    mostly here for when I come back to this months/years from now and
    I've forgotten how this code works. The other scenarios this is for --
    although very unlikely -- is other people new to the project and need
    a helping hand.

commit 2e602e9082
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 21:01:25 2021 +0100

    filter readings (over herz and light levels threshold).

    Having filtered down the list to readings which suppass the Hertz
    threshold (4+ per-second at time of writing), the code here filters it
    down even more. This bit of code searches for readings within this
    already filtered list for any readings which activate the light in the
    gallery (with the threshold matching that of 'gallery1' which in
    anything over 39). It then proceeds to save the results.

commit 80cf014c21
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 20:56:40 2021 +0100

    add save function for filtered flickers list.

    This could do with being generalised with the other save functions (in
    io_services). For now, it's job is to save the list of readings which
    contain four or more readings-per-second and at least one of them is
    over 39. The specificness of the 39 is because the test data used is
    from 'factory1' (Light Meter) and that is the threshold for triggering
    the lights connected to 'gallery1' in the gallery.

commit 7bfd06cf03
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 19:27:03 2021 +0100

    implement find_flicker feature.

    This functions goes through the list of readings and forms a
    dictionary of time-stamps, with light readings beyond a specified
    readings-per-second threshold, and the reading for said time-stamp.

    The results are then saved to the specified file, using
    'save_rps_totals' function.

commit 2cbecc0d2c
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 17:25:06 2021 +0100

    add save function for time-stamps with readings above threshold.

    This is not exactly encoded into the code itself. It's implied and
    needs to be used with that in mind. It's more of 'save list'
    function. I will probably rename/refactor this in the future depending
    on how the project develops.

commit 263bfe40fd
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 17:22:44 2021 +0100

    move 'data service' files to data_services file.

    Part of a move to clean-up flicker.py -- making it a place to call the
    functions in a way which is easy to 'switch' functions off via
    comments.

commit ee0853b3dd
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 16:37:50 2021 +0100

    create data_services.py

    Part of the move to clean-up flicker.py and make the code more
    modular (for potential improve in REPL usage?).

commit 0f6fdc22fa
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 16:35:50 2021 +0100

    add readings-per-sec.csv file to gitignore.

    It was getting in the way and doesn't need to be part of the commit
    history. It's only purpose is to output the results -- to be used else
    where.

commit d9742dc43b
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 16:30:54 2021 +0100

    remove redundant (save) code.

commit 9fb282db1f
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 16:30:07 2021 +0100

    move save_rps_totals function to io_services.

    Part of code clean-up.

commit 26b01f38f5
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 16:16:43 2021 +0100

    tally readings per second using list of tuples.

    This replaces the original way of doing it with a dictionary. The
    change was brought about because the previous data loading function
    was omitting duplicate entries (I.E. multiple readings from the same
    second in time).

commit a4f6142137
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 16:15:49 2021 +0100

    fix string interpolation bug in print_list function.

commit b149ce3a8d
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 16:02:14 2021 +0100

    change return type to list in load_raw_data.

    I made the mistake of not realising the dictionary was 'removing'
    duplicate entries by simply not adding the 'second' reading for a
    given time interval. An example of this is as follows,

    there are two readings within the fifty-sixth second (E.G. 07:03:56)
    but the second was being omitted from the dictionary storing the data
    after it was loaded into memory.

    I changed the return type to a list of tuples to preserve the raw part
    of the data (I.E. multiple readings per second). The intention here is
    so I can start from the 'raw' data without needing to load the data in
    numerous times during run-time. I've omitted the 'Id' column because I
    have no need for it in this context. If I do need it, though, I can
    add an extra item to the returned tuple (I.E. add r[0] to append) .

    This bug came about because I took most of the code from the initial
    'load data' function. The original function converted the raw CSV data
    into a dictionary which tallied the total readings per second before
    returning it. This function doesn't do that. It leaves the data in a
    more raw state.

commit 8f9df9462b
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 15:13:22 2021 +0100

    import io_services into flicker.py.

    I, also, removed the load_data function. This is part of the gradual
    move to transfer 'service' based functions out of flicker.py. The aim
    here is to reduce the need for duplicating code or make it easier to
    make function calls when needing a particular piece of data (or
    transformation of data).

commit 18d0470d43
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 15:11:32 2021 +0100

    create log_services.py.

    Houses a collection of print-based functions to help relay information
    in the terminal. The biggest motivation for this was to make the
    dictionaries easier to read when printing them in the terminal.

commit 47636b3b18
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 15:02:07 2021 +0100

    create io_services.py.

    The inital services files. This provides a function to load the CSV
    file of the raw test data (factory1 Light Meter).

commit 25277572c0
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 15:00:40 2021 +0100

    begin moving code to 'services'.

    I've began getting into a mess with trying to use duplicated code and
    data. I've began to move functions to their own services folder and
    files to help reduce the duplication.

commit b93a207ba3
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 13:13:40 2021 +0100

    rename reading-per-sec-tallies.csv to readings-per-sec.csv.

    Did this because for ease of typing.

commit 7c9feab1b2
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 13:11:52 2021 +0100

    put code into functions and 'main' in flicker.py.

    This is just so I can start to 'turn things on and off' (via
    comments).

commit 51f0d3e4bf
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 12:52:41 2021 +0100

    update file names to new test-data file names.

    This is part of a previous commit which shortended the file housing
    the test data.

commit f0cbce52f6
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 12:48:40 2021 +0100

    rename test data files.

    Because I'm only testing and getting a proof-of-concept up and
    running, the longer and more specific files is not worth the effort
    right now. They are unwieldy to type and getting in the way. I've
    renamed them to smaller names with the intention to use more specific
    file names when things start to settle in the direction of the
    project.

commit 9b87d742df
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 00:18:10 2021 +0100

    create 23-04-2021-readings-per-sec.csv ('results' file).

    This file houses the data flicker.py computes/generates.

commit e04617ae13
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 00:13:45 2021 +0100

    delete original flicker.py (moved to src).

    Just basic organisation. I accidently created flicker.py at the
    repositories root. I meant to create it in 'src'. I'd already pushed
    the commit before I spotted my mistake hence the 'mess' in the git
    history.

commit dc05b3481d
Author: Craig Oates <craig@craigoates.net>
Date:   Sat May 8 00:01:37 2021 +0100

    create flicker.py and csv parsing code.

    The code in this file is mostly to get the ball moving in this
    repository. This file opens the
    'light-meter-sample-readings-23-04-2021-ritherdon.csv' file and
    tallies-up the number of requests per second groups. After that, it
    writes the results to 23-04-2021-readings-per-sec.csv.

    As an example (to help explain), it counts and stores how many times
    the light meter (factory1) took a reading at the rate of two times per
    second. In this instance, there were 2955 instances of the light meter
    taking two readings per second. This roughly equates to 10% of the
    days readings was at a rate of two requests per second. 28% of the
    time the light meter was recording at four requests per second, 18%
    for one and 44% for three.

commit 77ee5318ec
Author: Craig Oates <craig@craigoates.net>
Date:   Fri May 7 23:59:10 2021 +0100

    create 'lite' sample data set.

    The main file I was using was too big and taking too long to
    process. Whilst I got things moving in this repository, I removed a
    lot of the data to help speed-up the development process. This should
    be a temporary file and I expect this to be deleted at some point in
    the future.

commit aeaf2dc258
Author: Craig Oates <craig@craigoates.net>
Date:   Fri May 7 20:27:02 2021 +0100

    create flicker.py.

    This is the 'main' file if you will.

commit 734097fcc9
Author: Craig Oates <craig@craigoates.net>
Date:   Fri May 7 20:17:24 2021 +0100

    import initial light meter readings 23-04-2021.

    This is a .csv file and will be used and the initial test data this
    project will aim to breakdown into a list of readings for each
    second. At the moment, I'm being vague with my desciption of what
    'breakdown' means here because this is just a proof-of-concept. I
    don't expect this file to remain around for too long in the
    repository.

commit 0078370093
Author: Craig Oates <craig@craigoates.net>
Date:   Fri May 7 20:16:01 2021 +0100

    create requirements.txt.
master
Craig Oates 3 years ago
parent
commit
e923a821af
  1. 1
      .gitignore
  2. 0
      requirements.txt
  3. 286
      src/data/test-data-lite.csv
  4. 84295
      src/data/test-data.csv
  5. 72
      src/flicker.py
  6. 50
      src/services/data_services.py
  7. 29
      src/services/io_services.py
  8. 16
      src/services/log_services.py

1
.gitignore vendored

@ -138,3 +138,4 @@ dmypy.json
# Cython debug symbols
cython_debug/
/src/data/results/

0
requirements.txt

286
src/data/test-data-lite.csv

@ -0,0 +1,286 @@
Id,Time Stamp,Reading
7780344,2021-04-23 06:57:54.000000,-96
7780345,2021-04-23 06:58:20.000000,-20
7780346,2021-04-23 06:58:25.000000,-4
7780347,2021-04-23 06:58:30.000000,-3
7780348,2021-04-23 06:58:34.000000,-2
7780349,2021-04-23 06:58:38.000000,-1
7780350,2021-04-23 06:58:42.000000,-1
7780351,2021-04-23 06:58:46.000000,0
7780352,2021-04-23 06:58:50.000000,0
7780353,2021-04-23 06:58:54.000000,0
7780354,2021-04-23 06:58:57.000000,0
7780355,2021-04-23 06:59:01.000000,0
7780356,2021-04-23 06:59:04.000000,0
7780357,2021-04-23 06:59:08.000000,0
7780358,2021-04-23 06:59:11.000000,0
7780359,2021-04-23 06:59:15.000000,0
7780360,2021-04-23 06:59:18.000000,0
7780361,2021-04-23 06:59:21.000000,0
7780362,2021-04-23 06:59:25.000000,0
7780363,2021-04-23 06:59:28.000000,0
7780364,2021-04-23 06:59:31.000000,0
7780365,2021-04-23 06:59:35.000000,0
7780366,2021-04-23 06:59:38.000000,0
7780367,2021-04-23 06:59:41.000000,0
7780368,2021-04-23 06:59:45.000000,0
7780369,2021-04-23 06:59:48.000000,0
7780370,2021-04-23 06:59:51.000000,0
7780371,2021-04-23 06:59:55.000000,0
7780372,2021-04-23 06:59:58.000000,0
7780373,2021-04-23 07:00:01.000000,0
7780374,2021-04-23 07:00:05.000000,0
7780375,2021-04-23 07:00:08.000000,0
7780376,2021-04-23 07:00:11.000000,0
7780377,2021-04-23 07:00:14.000000,0
7780378,2021-04-23 07:00:18.000000,0
7780379,2021-04-23 07:00:20.000000,5
7780380,2021-04-23 07:00:21.000000,11
7780381,2021-04-23 07:00:22.000000,11
7780382,2021-04-23 07:00:24.000000,11
7780383,2021-04-23 07:00:25.000000,11
7780384,2021-04-23 07:00:26.000000,11
7780385,2021-04-23 07:00:27.000000,11
7780386,2021-04-23 07:00:29.000000,11
7780387,2021-04-23 07:00:30.000000,12
7780388,2021-04-23 07:00:31.000000,12
7780389,2021-04-23 07:00:32.000000,12
7780390,2021-04-23 07:00:33.000000,12
7780391,2021-04-23 07:00:35.000000,12
7780392,2021-04-23 07:00:36.000000,12
7780393,2021-04-23 07:00:37.000000,12
7780394,2021-04-23 07:00:38.000000,12
7780395,2021-04-23 07:00:39.000000,12
7780396,2021-04-23 07:00:40.000000,12
7780397,2021-04-23 07:00:42.000000,12
7780398,2021-04-23 07:00:43.000000,12
7780399,2021-04-23 07:00:44.000000,12
7780400,2021-04-23 07:00:45.000000,13
7780401,2021-04-23 07:00:46.000000,13
7780402,2021-04-23 07:00:47.000000,13
7780403,2021-04-23 07:00:48.000000,13
7780404,2021-04-23 07:00:49.000000,13
7780405,2021-04-23 07:00:51.000000,13
7780406,2021-04-23 07:00:52.000000,13
7780407,2021-04-23 07:00:53.000000,13
7780408,2021-04-23 07:00:54.000000,13
7780409,2021-04-23 07:00:55.000000,13
7780410,2021-04-23 07:00:56.000000,13
7780411,2021-04-23 07:00:57.000000,13
7780412,2021-04-23 07:00:58.000000,13
7780413,2021-04-23 07:00:59.000000,13
7780414,2021-04-23 07:01:00.000000,13
7780415,2021-04-23 07:01:01.000000,13
7780416,2021-04-23 07:01:02.000000,14
7780417,2021-04-23 07:01:03.000000,14
7780418,2021-04-23 07:01:04.000000,14
7780419,2021-04-23 07:01:05.000000,14
7780420,2021-04-23 07:01:06.000000,14
7780421,2021-04-23 07:01:07.000000,14
7780422,2021-04-23 07:01:08.000000,14
7780423,2021-04-23 07:01:09.000000,14
7780424,2021-04-23 07:01:10.000000,14
7780425,2021-04-23 07:01:11.000000,14
7780426,2021-04-23 07:01:12.000000,14
7780427,2021-04-23 07:01:13.000000,14
7780428,2021-04-23 07:01:14.000000,14
7780429,2021-04-23 07:01:15.000000,14
7780430,2021-04-23 07:01:16.000000,14
7780431,2021-04-23 07:01:17.000000,14
7780432,2021-04-23 07:01:18.000000,14
7780433,2021-04-23 07:01:19.000000,14
7780434,2021-04-23 07:01:20.000000,15
7780435,2021-04-23 07:01:21.000000,15
7780436,2021-04-23 07:01:22.000000,15
7780437,2021-04-23 07:01:23.000000,15
7780438,2021-04-23 07:01:24.000000,15
7780439,2021-04-23 07:01:25.000000,15
7780440,2021-04-23 07:01:26.000000,15
7780441,2021-04-23 07:01:27.000000,15
7780442,2021-04-23 07:01:28.000000,15
7780443,2021-04-23 07:01:29.000000,15
7780444,2021-04-23 07:01:30.000000,15
7780445,2021-04-23 07:01:31.000000,15
7780446,2021-04-23 07:01:31.000000,15
7780447,2021-04-23 07:01:32.000000,15
7780448,2021-04-23 07:01:33.000000,15
7780449,2021-04-23 07:01:34.000000,15
7780450,2021-04-23 07:01:35.000000,15
7780451,2021-04-23 07:01:36.000000,15
7780452,2021-04-23 07:01:37.000000,15
7780453,2021-04-23 07:01:38.000000,15
7780454,2021-04-23 07:01:39.000000,15
7780455,2021-04-23 07:01:40.000000,16
7780456,2021-04-23 07:01:40.000000,16
7780457,2021-04-23 07:01:41.000000,16
7780458,2021-04-23 07:01:42.000000,16
7780459,2021-04-23 07:01:43.000000,16
7780460,2021-04-23 07:01:44.000000,16
7780461,2021-04-23 07:01:45.000000,16
7780462,2021-04-23 07:01:46.000000,16
7780463,2021-04-23 07:01:47.000000,16
7780464,2021-04-23 07:01:47.000000,16
7780465,2021-04-23 07:01:48.000000,16
7780466,2021-04-23 07:01:49.000000,16
7780467,2021-04-23 07:01:50.000000,16
7780468,2021-04-23 07:01:51.000000,16
7780469,2021-04-23 07:01:52.000000,16
7780470,2021-04-23 07:01:53.000000,16
7780471,2021-04-23 07:01:54.000000,16
7780472,2021-04-23 07:01:54.000000,16
7780473,2021-04-23 07:01:55.000000,16
7780474,2021-04-23 07:01:56.000000,16
7780475,2021-04-23 07:01:57.000000,16
7780476,2021-04-23 07:01:58.000000,16
7780477,2021-04-23 07:01:59.000000,16
7780478,2021-04-23 07:02:00.000000,16
7780479,2021-04-23 07:02:00.000000,16
7780480,2021-04-23 07:02:01.000000,16
7780481,2021-04-23 07:02:02.000000,16
7780482,2021-04-23 07:02:03.000000,16
7780483,2021-04-23 07:02:04.000000,16
7780484,2021-04-23 07:02:05.000000,16
7780485,2021-04-23 07:02:05.000000,16
7780486,2021-04-23 07:02:06.000000,16
7780487,2021-04-23 07:02:07.000000,16
7780488,2021-04-23 07:02:08.000000,16
7780489,2021-04-23 07:02:09.000000,16
7780490,2021-04-23 07:02:10.000000,16
7780491,2021-04-23 07:02:10.000000,16
7780492,2021-04-23 07:02:11.000000,16
7780493,2021-04-23 07:02:12.000000,16
7780494,2021-04-23 07:02:13.000000,16
7780495,2021-04-23 07:02:14.000000,16
7780496,2021-04-23 07:02:15.000000,17
7780497,2021-04-23 07:02:15.000000,17
7780498,2021-04-23 07:02:16.000000,17
7780499,2021-04-23 07:02:17.000000,17
7780500,2021-04-23 07:02:18.000000,17
7780501,2021-04-23 07:02:19.000000,17
7780502,2021-04-23 07:02:20.000000,17
7780503,2021-04-23 07:02:20.000000,17
7780504,2021-04-23 07:02:21.000000,17
7780505,2021-04-23 07:02:22.000000,17
7780506,2021-04-23 07:02:23.000000,17
7780507,2021-04-23 07:02:24.000000,17
7780508,2021-04-23 07:02:25.000000,17
7780509,2021-04-23 07:02:25.000000,17
7780510,2021-04-23 07:02:26.000000,17
7780511,2021-04-23 07:02:27.000000,17
7780512,2021-04-23 07:02:28.000000,17
7780513,2021-04-23 07:02:29.000000,17
7780514,2021-04-23 07:02:30.000000,17
7780515,2021-04-23 07:02:30.000000,17
7780516,2021-04-23 07:02:31.000000,17
7780517,2021-04-23 07:02:32.000000,17
7780518,2021-04-23 07:02:33.000000,17
7780519,2021-04-23 07:02:34.000000,17
7780520,2021-04-23 07:02:34.000000,17
7780521,2021-04-23 07:02:35.000000,17
7780522,2021-04-23 07:02:36.000000,17
7780523,2021-04-23 07:02:37.000000,17
7780524,2021-04-23 07:02:38.000000,17
7780525,2021-04-23 07:02:39.000000,17
7780526,2021-04-23 07:02:39.000000,17
7780527,2021-04-23 07:02:40.000000,17
7780528,2021-04-23 07:02:41.000000,17
7780529,2021-04-23 07:02:42.000000,17
7780530,2021-04-23 07:02:43.000000,17
7780531,2021-04-23 07:02:43.000000,17
7780532,2021-04-23 07:02:44.000000,17
7780533,2021-04-23 07:02:45.000000,17
7780534,2021-04-23 07:02:46.000000,17
7780535,2021-04-23 07:02:47.000000,17
7780536,2021-04-23 07:02:47.000000,17
7780537,2021-04-23 07:02:48.000000,17
7780538,2021-04-23 07:02:49.000000,17
7780539,2021-04-23 07:02:50.000000,17
7780540,2021-04-23 07:02:51.000000,17
7780541,2021-04-23 07:02:51.000000,17
7780542,2021-04-23 07:02:52.000000,17
7780543,2021-04-23 07:02:53.000000,17
7780544,2021-04-23 07:02:54.000000,17
7780545,2021-04-23 07:02:55.000000,17
7780546,2021-04-23 07:02:55.000000,17
7780547,2021-04-23 07:02:56.000000,17
7780548,2021-04-23 07:02:57.000000,17
7780549,2021-04-23 07:02:58.000000,17
7780550,2021-04-23 07:02:59.000000,17
7780551,2021-04-23 07:02:59.000000,17
7780552,2021-04-23 07:03:00.000000,17
7780553,2021-04-23 07:03:01.000000,17
7780554,2021-04-23 07:03:02.000000,17
7780555,2021-04-23 07:03:03.000000,17
7780556,2021-04-23 07:03:03.000000,17
7780557,2021-04-23 07:03:04.000000,17
7780558,2021-04-23 07:03:05.000000,17
7780559,2021-04-23 07:03:06.000000,17
7780560,2021-04-23 07:03:06.000000,17
7780561,2021-04-23 07:03:07.000000,17
7780562,2021-04-23 07:03:08.000000,17
7780563,2021-04-23 07:03:09.000000,17
7780564,2021-04-23 07:03:10.000000,17
7780565,2021-04-23 07:03:10.000000,17
7780566,2021-04-23 07:03:11.000000,17
7780567,2021-04-23 07:03:12.000000,17
7780568,2021-04-23 07:03:13.000000,17
7780569,2021-04-23 07:03:14.000000,17
7780570,2021-04-23 07:03:14.000000,17
7780571,2021-04-23 07:03:15.000000,17
7780572,2021-04-23 07:03:16.000000,17
7780573,2021-04-23 07:03:17.000000,17
7780574,2021-04-23 07:03:17.000000,17
7780575,2021-04-23 07:03:18.000000,17
7780576,2021-04-23 07:03:19.000000,17
7780577,2021-04-23 07:03:20.000000,17
7780578,2021-04-23 07:03:21.000000,17
7780579,2021-04-23 07:03:21.000000,17
7780580,2021-04-23 07:03:22.000000,17
7780581,2021-04-23 07:03:23.000000,17
7780582,2021-04-23 07:03:24.000000,17
7780583,2021-04-23 07:03:25.000000,17
7780584,2021-04-23 07:03:25.000000,17
7780585,2021-04-23 07:03:26.000000,17
7780586,2021-04-23 07:03:27.000000,17
7780587,2021-04-23 07:03:28.000000,17
7780588,2021-04-23 07:03:28.000000,17
7780589,2021-04-23 07:03:29.000000,17
7780590,2021-04-23 07:03:30.000000,17
7780591,2021-04-23 07:03:31.000000,17
7780592,2021-04-23 07:03:32.000000,17
7780593,2021-04-23 07:03:32.000000,17
7780594,2021-04-23 07:03:33.000000,17
7780595,2021-04-23 07:03:34.000000,17
7780596,2021-04-23 07:03:35.000000,17
7780597,2021-04-23 07:03:35.000000,17
7780598,2021-04-23 07:03:36.000000,17
7780599,2021-04-23 07:03:37.000000,17
7780600,2021-04-23 07:03:38.000000,17
7780601,2021-04-23 07:03:39.000000,17
7780602,2021-04-23 07:03:39.000000,17
7780603,2021-04-23 07:03:40.000000,17
7780604,2021-04-23 07:03:41.000000,17
7780605,2021-04-23 07:03:42.000000,17
7780606,2021-04-23 07:03:42.000000,17
7780607,2021-04-23 07:03:43.000000,17
7780608,2021-04-23 07:03:44.000000,17
7780609,2021-04-23 07:03:45.000000,17
7780610,2021-04-23 07:03:46.000000,17
7780611,2021-04-23 07:03:46.000000,17
7780612,2021-04-23 07:03:47.000000,17
7780613,2021-04-23 07:03:48.000000,17
7780614,2021-04-23 07:03:49.000000,17
7780615,2021-04-23 07:03:49.000000,17
7780616,2021-04-23 07:03:50.000000,17
7780617,2021-04-23 07:03:51.000000,17
7780618,2021-04-23 07:03:52.000000,17
7780619,2021-04-23 07:03:53.000000,17
7780620,2021-04-23 07:03:53.000000,17
7780621,2021-04-23 07:03:54.000000,17
7780622,2021-04-23 07:03:55.000000,17
7780623,2021-04-23 07:03:56.000000,17
7780624,2021-04-23 07:03:56.000000,17
7780625,2021-04-23 07:03:57.000000,17
7780626,2021-04-23 07:03:58.000000,17
7780627,2021-04-23 07:03:59.000000,17
7780628,2021-04-23 07:04:00.000000,17
1 Id Time Stamp Reading
2 7780344 2021-04-23 06:57:54.000000 -96
3 7780345 2021-04-23 06:58:20.000000 -20
4 7780346 2021-04-23 06:58:25.000000 -4
5 7780347 2021-04-23 06:58:30.000000 -3
6 7780348 2021-04-23 06:58:34.000000 -2
7 7780349 2021-04-23 06:58:38.000000 -1
8 7780350 2021-04-23 06:58:42.000000 -1
9 7780351 2021-04-23 06:58:46.000000 0
10 7780352 2021-04-23 06:58:50.000000 0
11 7780353 2021-04-23 06:58:54.000000 0
12 7780354 2021-04-23 06:58:57.000000 0
13 7780355 2021-04-23 06:59:01.000000 0
14 7780356 2021-04-23 06:59:04.000000 0
15 7780357 2021-04-23 06:59:08.000000 0
16 7780358 2021-04-23 06:59:11.000000 0
17 7780359 2021-04-23 06:59:15.000000 0
18 7780360 2021-04-23 06:59:18.000000 0
19 7780361 2021-04-23 06:59:21.000000 0
20 7780362 2021-04-23 06:59:25.000000 0
21 7780363 2021-04-23 06:59:28.000000 0
22 7780364 2021-04-23 06:59:31.000000 0
23 7780365 2021-04-23 06:59:35.000000 0
24 7780366 2021-04-23 06:59:38.000000 0
25 7780367 2021-04-23 06:59:41.000000 0
26 7780368 2021-04-23 06:59:45.000000 0
27 7780369 2021-04-23 06:59:48.000000 0
28 7780370 2021-04-23 06:59:51.000000 0
29 7780371 2021-04-23 06:59:55.000000 0
30 7780372 2021-04-23 06:59:58.000000 0
31 7780373 2021-04-23 07:00:01.000000 0
32 7780374 2021-04-23 07:00:05.000000 0
33 7780375 2021-04-23 07:00:08.000000 0
34 7780376 2021-04-23 07:00:11.000000 0
35 7780377 2021-04-23 07:00:14.000000 0
36 7780378 2021-04-23 07:00:18.000000 0
37 7780379 2021-04-23 07:00:20.000000 5
38 7780380 2021-04-23 07:00:21.000000 11
39 7780381 2021-04-23 07:00:22.000000 11
40 7780382 2021-04-23 07:00:24.000000 11
41 7780383 2021-04-23 07:00:25.000000 11
42 7780384 2021-04-23 07:00:26.000000 11
43 7780385 2021-04-23 07:00:27.000000 11
44 7780386 2021-04-23 07:00:29.000000 11
45 7780387 2021-04-23 07:00:30.000000 12
46 7780388 2021-04-23 07:00:31.000000 12
47 7780389 2021-04-23 07:00:32.000000 12
48 7780390 2021-04-23 07:00:33.000000 12
49 7780391 2021-04-23 07:00:35.000000 12
50 7780392 2021-04-23 07:00:36.000000 12
51 7780393 2021-04-23 07:00:37.000000 12
52 7780394 2021-04-23 07:00:38.000000 12
53 7780395 2021-04-23 07:00:39.000000 12
54 7780396 2021-04-23 07:00:40.000000 12
55 7780397 2021-04-23 07:00:42.000000 12
56 7780398 2021-04-23 07:00:43.000000 12
57 7780399 2021-04-23 07:00:44.000000 12
58 7780400 2021-04-23 07:00:45.000000 13
59 7780401 2021-04-23 07:00:46.000000 13
60 7780402 2021-04-23 07:00:47.000000 13
61 7780403 2021-04-23 07:00:48.000000 13
62 7780404 2021-04-23 07:00:49.000000 13
63 7780405 2021-04-23 07:00:51.000000 13
64 7780406 2021-04-23 07:00:52.000000 13
65 7780407 2021-04-23 07:00:53.000000 13
66 7780408 2021-04-23 07:00:54.000000 13
67 7780409 2021-04-23 07:00:55.000000 13
68 7780410 2021-04-23 07:00:56.000000 13
69 7780411 2021-04-23 07:00:57.000000 13
70 7780412 2021-04-23 07:00:58.000000 13
71 7780413 2021-04-23 07:00:59.000000 13
72 7780414 2021-04-23 07:01:00.000000 13
73 7780415 2021-04-23 07:01:01.000000 13
74 7780416 2021-04-23 07:01:02.000000 14
75 7780417 2021-04-23 07:01:03.000000 14
76 7780418 2021-04-23 07:01:04.000000 14
77 7780419 2021-04-23 07:01:05.000000 14
78 7780420 2021-04-23 07:01:06.000000 14
79 7780421 2021-04-23 07:01:07.000000 14
80 7780422 2021-04-23 07:01:08.000000 14
81 7780423 2021-04-23 07:01:09.000000 14
82 7780424 2021-04-23 07:01:10.000000 14
83 7780425 2021-04-23 07:01:11.000000 14
84 7780426 2021-04-23 07:01:12.000000 14
85 7780427 2021-04-23 07:01:13.000000 14
86 7780428 2021-04-23 07:01:14.000000 14
87 7780429 2021-04-23 07:01:15.000000 14
88 7780430 2021-04-23 07:01:16.000000 14
89 7780431 2021-04-23 07:01:17.000000 14
90 7780432 2021-04-23 07:01:18.000000 14
91 7780433 2021-04-23 07:01:19.000000 14
92 7780434 2021-04-23 07:01:20.000000 15
93 7780435 2021-04-23 07:01:21.000000 15
94 7780436 2021-04-23 07:01:22.000000 15
95 7780437 2021-04-23 07:01:23.000000 15
96 7780438 2021-04-23 07:01:24.000000 15
97 7780439 2021-04-23 07:01:25.000000 15
98 7780440 2021-04-23 07:01:26.000000 15
99 7780441 2021-04-23 07:01:27.000000 15
100 7780442 2021-04-23 07:01:28.000000 15
101 7780443 2021-04-23 07:01:29.000000 15
102 7780444 2021-04-23 07:01:30.000000 15
103 7780445 2021-04-23 07:01:31.000000 15
104 7780446 2021-04-23 07:01:31.000000 15
105 7780447 2021-04-23 07:01:32.000000 15
106 7780448 2021-04-23 07:01:33.000000 15
107 7780449 2021-04-23 07:01:34.000000 15
108 7780450 2021-04-23 07:01:35.000000 15
109 7780451 2021-04-23 07:01:36.000000 15
110 7780452 2021-04-23 07:01:37.000000 15
111 7780453 2021-04-23 07:01:38.000000 15
112 7780454 2021-04-23 07:01:39.000000 15
113 7780455 2021-04-23 07:01:40.000000 16
114 7780456 2021-04-23 07:01:40.000000 16
115 7780457 2021-04-23 07:01:41.000000 16
116 7780458 2021-04-23 07:01:42.000000 16
117 7780459 2021-04-23 07:01:43.000000 16
118 7780460 2021-04-23 07:01:44.000000 16
119 7780461 2021-04-23 07:01:45.000000 16
120 7780462 2021-04-23 07:01:46.000000 16
121 7780463 2021-04-23 07:01:47.000000 16
122 7780464 2021-04-23 07:01:47.000000 16
123 7780465 2021-04-23 07:01:48.000000 16
124 7780466 2021-04-23 07:01:49.000000 16
125 7780467 2021-04-23 07:01:50.000000 16
126 7780468 2021-04-23 07:01:51.000000 16
127 7780469 2021-04-23 07:01:52.000000 16
128 7780470 2021-04-23 07:01:53.000000 16
129 7780471 2021-04-23 07:01:54.000000 16
130 7780472 2021-04-23 07:01:54.000000 16
131 7780473 2021-04-23 07:01:55.000000 16
132 7780474 2021-04-23 07:01:56.000000 16
133 7780475 2021-04-23 07:01:57.000000 16
134 7780476 2021-04-23 07:01:58.000000 16
135 7780477 2021-04-23 07:01:59.000000 16
136 7780478 2021-04-23 07:02:00.000000 16
137 7780479 2021-04-23 07:02:00.000000 16
138 7780480 2021-04-23 07:02:01.000000 16
139 7780481 2021-04-23 07:02:02.000000 16
140 7780482 2021-04-23 07:02:03.000000 16
141 7780483 2021-04-23 07:02:04.000000 16
142 7780484 2021-04-23 07:02:05.000000 16
143 7780485 2021-04-23 07:02:05.000000 16
144 7780486 2021-04-23 07:02:06.000000 16
145 7780487 2021-04-23 07:02:07.000000 16
146 7780488 2021-04-23 07:02:08.000000 16
147 7780489 2021-04-23 07:02:09.000000 16
148 7780490 2021-04-23 07:02:10.000000 16
149 7780491 2021-04-23 07:02:10.000000 16
150 7780492 2021-04-23 07:02:11.000000 16
151 7780493 2021-04-23 07:02:12.000000 16
152 7780494 2021-04-23 07:02:13.000000 16
153 7780495 2021-04-23 07:02:14.000000 16
154 7780496 2021-04-23 07:02:15.000000 17
155 7780497 2021-04-23 07:02:15.000000 17
156 7780498 2021-04-23 07:02:16.000000 17
157 7780499 2021-04-23 07:02:17.000000 17
158 7780500 2021-04-23 07:02:18.000000 17
159 7780501 2021-04-23 07:02:19.000000 17
160 7780502 2021-04-23 07:02:20.000000 17
161 7780503 2021-04-23 07:02:20.000000 17
162 7780504 2021-04-23 07:02:21.000000 17
163 7780505 2021-04-23 07:02:22.000000 17
164 7780506 2021-04-23 07:02:23.000000 17
165 7780507 2021-04-23 07:02:24.000000 17
166 7780508 2021-04-23 07:02:25.000000 17
167 7780509 2021-04-23 07:02:25.000000 17
168 7780510 2021-04-23 07:02:26.000000 17
169 7780511 2021-04-23 07:02:27.000000 17
170 7780512 2021-04-23 07:02:28.000000 17
171 7780513 2021-04-23 07:02:29.000000 17
172 7780514 2021-04-23 07:02:30.000000 17
173 7780515 2021-04-23 07:02:30.000000 17
174 7780516 2021-04-23 07:02:31.000000 17
175 7780517 2021-04-23 07:02:32.000000 17
176 7780518 2021-04-23 07:02:33.000000 17
177 7780519 2021-04-23 07:02:34.000000 17
178 7780520 2021-04-23 07:02:34.000000 17
179 7780521 2021-04-23 07:02:35.000000 17
180 7780522 2021-04-23 07:02:36.000000 17
181 7780523 2021-04-23 07:02:37.000000 17
182 7780524 2021-04-23 07:02:38.000000 17
183 7780525 2021-04-23 07:02:39.000000 17
184 7780526 2021-04-23 07:02:39.000000 17
185 7780527 2021-04-23 07:02:40.000000 17
186 7780528 2021-04-23 07:02:41.000000 17
187 7780529 2021-04-23 07:02:42.000000 17
188 7780530 2021-04-23 07:02:43.000000 17
189 7780531 2021-04-23 07:02:43.000000 17
190 7780532 2021-04-23 07:02:44.000000 17
191 7780533 2021-04-23 07:02:45.000000 17
192 7780534 2021-04-23 07:02:46.000000 17
193 7780535 2021-04-23 07:02:47.000000 17
194 7780536 2021-04-23 07:02:47.000000 17
195 7780537 2021-04-23 07:02:48.000000 17
196 7780538 2021-04-23 07:02:49.000000 17
197 7780539 2021-04-23 07:02:50.000000 17
198 7780540 2021-04-23 07:02:51.000000 17
199 7780541 2021-04-23 07:02:51.000000 17
200 7780542 2021-04-23 07:02:52.000000 17
201 7780543 2021-04-23 07:02:53.000000 17
202 7780544 2021-04-23 07:02:54.000000 17
203 7780545 2021-04-23 07:02:55.000000 17
204 7780546 2021-04-23 07:02:55.000000 17
205 7780547 2021-04-23 07:02:56.000000 17
206 7780548 2021-04-23 07:02:57.000000 17
207 7780549 2021-04-23 07:02:58.000000 17
208 7780550 2021-04-23 07:02:59.000000 17
209 7780551 2021-04-23 07:02:59.000000 17
210 7780552 2021-04-23 07:03:00.000000 17
211 7780553 2021-04-23 07:03:01.000000 17
212 7780554 2021-04-23 07:03:02.000000 17
213 7780555 2021-04-23 07:03:03.000000 17
214 7780556 2021-04-23 07:03:03.000000 17
215 7780557 2021-04-23 07:03:04.000000 17
216 7780558 2021-04-23 07:03:05.000000 17
217 7780559 2021-04-23 07:03:06.000000 17
218 7780560 2021-04-23 07:03:06.000000 17
219 7780561 2021-04-23 07:03:07.000000 17
220 7780562 2021-04-23 07:03:08.000000 17
221 7780563 2021-04-23 07:03:09.000000 17
222 7780564 2021-04-23 07:03:10.000000 17
223 7780565 2021-04-23 07:03:10.000000 17
224 7780566 2021-04-23 07:03:11.000000 17
225 7780567 2021-04-23 07:03:12.000000 17
226 7780568 2021-04-23 07:03:13.000000 17
227 7780569 2021-04-23 07:03:14.000000 17
228 7780570 2021-04-23 07:03:14.000000 17
229 7780571 2021-04-23 07:03:15.000000 17
230 7780572 2021-04-23 07:03:16.000000 17
231 7780573 2021-04-23 07:03:17.000000 17
232 7780574 2021-04-23 07:03:17.000000 17
233 7780575 2021-04-23 07:03:18.000000 17
234 7780576 2021-04-23 07:03:19.000000 17
235 7780577 2021-04-23 07:03:20.000000 17
236 7780578 2021-04-23 07:03:21.000000 17
237 7780579 2021-04-23 07:03:21.000000 17
238 7780580 2021-04-23 07:03:22.000000 17
239 7780581 2021-04-23 07:03:23.000000 17
240 7780582 2021-04-23 07:03:24.000000 17
241 7780583 2021-04-23 07:03:25.000000 17
242 7780584 2021-04-23 07:03:25.000000 17
243 7780585 2021-04-23 07:03:26.000000 17
244 7780586 2021-04-23 07:03:27.000000 17
245 7780587 2021-04-23 07:03:28.000000 17
246 7780588 2021-04-23 07:03:28.000000 17
247 7780589 2021-04-23 07:03:29.000000 17
248 7780590 2021-04-23 07:03:30.000000 17
249 7780591 2021-04-23 07:03:31.000000 17
250 7780592 2021-04-23 07:03:32.000000 17
251 7780593 2021-04-23 07:03:32.000000 17
252 7780594 2021-04-23 07:03:33.000000 17
253 7780595 2021-04-23 07:03:34.000000 17
254 7780596 2021-04-23 07:03:35.000000 17
255 7780597 2021-04-23 07:03:35.000000 17
256 7780598 2021-04-23 07:03:36.000000 17
257 7780599 2021-04-23 07:03:37.000000 17
258 7780600 2021-04-23 07:03:38.000000 17
259 7780601 2021-04-23 07:03:39.000000 17
260 7780602 2021-04-23 07:03:39.000000 17
261 7780603 2021-04-23 07:03:40.000000 17
262 7780604 2021-04-23 07:03:41.000000 17
263 7780605 2021-04-23 07:03:42.000000 17
264 7780606 2021-04-23 07:03:42.000000 17
265 7780607 2021-04-23 07:03:43.000000 17
266 7780608 2021-04-23 07:03:44.000000 17
267 7780609 2021-04-23 07:03:45.000000 17
268 7780610 2021-04-23 07:03:46.000000 17
269 7780611 2021-04-23 07:03:46.000000 17
270 7780612 2021-04-23 07:03:47.000000 17
271 7780613 2021-04-23 07:03:48.000000 17
272 7780614 2021-04-23 07:03:49.000000 17
273 7780615 2021-04-23 07:03:49.000000 17
274 7780616 2021-04-23 07:03:50.000000 17
275 7780617 2021-04-23 07:03:51.000000 17
276 7780618 2021-04-23 07:03:52.000000 17
277 7780619 2021-04-23 07:03:53.000000 17
278 7780620 2021-04-23 07:03:53.000000 17
279 7780621 2021-04-23 07:03:54.000000 17
280 7780622 2021-04-23 07:03:55.000000 17
281 7780623 2021-04-23 07:03:56.000000 17
282 7780624 2021-04-23 07:03:56.000000 17
283 7780625 2021-04-23 07:03:57.000000 17
284 7780626 2021-04-23 07:03:58.000000 17
285 7780627 2021-04-23 07:03:59.000000 17
286 7780628 2021-04-23 07:04:00.000000 17

84295
src/data/test-data.csv

File diff suppressed because it is too large Load Diff

72
src/flicker.py

@ -0,0 +1,72 @@
from services import io_services, log_services, data_services
def main():
# File paths used to save and load the data.
raw_data_path = "data/test-data.csv"
rps_save_path = "data/results/readings-per-sec.csv"
rps_above_thresh = "data/results/readings_above_threshold.csv"
flicker_list = "data/results/flicker_list.csv"
filtered_flickers = "data/results/filtered_flicker_entries.csv"
# Step 1
# ======
# Load the raw data, taken from the exported database.
raw_data = io_services.load_raw_data(raw_data_path)
# log_services.print_list(raw_data)
# Step 2
# ======
# Tally-up how many readings occured for each second in the
# raw data. For example, for the period between 2021-04-23
# 07:03:57 and 2021-04-23 07:03:58, how many readings did the
# system take? Was it 1, 3, Etc.
time_tallies = data_services.tally_readings_per_second(raw_data)
# log_services.print_dictionary(time_tallies)
# Step 3
# ======
# Count the number of tallies derived from step 2. So, how
# many time did the system take 2 readings-per-second, how many
# times did the system 3 readings-per-second Etc.
rps_totals = data_services.total_count_for_each_reading_per_second(time_tallies)
# log_services.print_dictionary(rps_totals)
io_services.save_rps_totals(rps_totals, rps_save_path)
# Step 4
# ======
# List out all the time periods which had more than the
# specified readings-per-second. The default value is any time
# period with more than 4 readings-per-second but you can change
# it (it's a function argument).
rps_above_hertz = data_services.get_rps_above(4, time_tallies)
# log_services.print_list(rps_above_two)
io_services.save_rps_above_threshold(rps_above_hertz, rps_above_thresh)
# Step 5
# ======
# Using the list of time periods derived in step 4
# (rps_above_hertz), create a new list from the raw data (step
# 1). Filter out the time periods created in step 4 and include
# all their readings for that time period (I.E. second). An
# example of this is: The list created in step 4 shows the time
# period between 2021-04-23 07:03:57 and 2021-04-23 07:03:58 has 4
# readings so note the (start) time and how the readings recorded
# in that period.
flicker_entries = data_services.find_flickers(rps_above_hertz, raw_data)
# log_services.print_dictionary(flicker_tallies)
io_services.save_rps_totals(flicker_entries, flicker_list)
# Step 6
# =======
# This step filters out the time periods which pass the hertz
# threshold to those which have at least one reading in its (1
# second period) grouping to cause the light to turn on in the
# gallery ('gallery1'). If this list contains any readings, you
# can review them to make sure the light doesn't turn on and off
# enough times to potentially cause a photo-epileptic seizure.
filtered_flicker_entries = data_services.find_readings_with_lights_on(flicker_entries)
# log_services.print_list(filtered_flicker_entries)
io_services.save_filtered_flickers(filtered_flicker_entries, filtered_flickers)
if __name__ == "__main__":
main()

50
src/services/data_services.py

@ -0,0 +1,50 @@
def tally_readings_per_second(data):
time_tallies = dict()
for item in data:
key = item[0]
if (key in time_tallies):
time_tallies[key] = time_tallies[key] + 1
else:
time_tallies[key] = 1
return time_tallies
def total_count_for_each_reading_per_second(time_tallies):
tally_totals = dict()
for val in time_tallies.values():
if (val in tally_totals):
tally_totals[val] = (tally_totals[val]) + 1
else:
tally_totals[val] = 1
return tally_totals
def get_rps_above(threshold, readings):
times = list()
for k, v in readings.items():
if (v >= threshold):
times.append(k)
return times
def find_flickers(selected_readings, all_readings):
selected = dict()
for current_selected_reading in selected_readings:
readings = list()
for current_reading in all_readings:
if (current_selected_reading == current_reading[0]):
readings.append(current_reading[1])
selected[current_selected_reading] = readings
return selected
def find_readings_with_lights_on(flicker_entries):
filtered_readings = list()
add_to_list = False
for time, reading in flicker_entries.items():
for item in reading:
val = int(item)
if (val > 39):
add_to_list = True
break
else:
add_to_list = False
if (add_to_list == True):
filtered_readings.append( (time, reading) )
return filtered_readings

29
src/services/io_services.py

@ -0,0 +1,29 @@
import csv
import datetime
def load_raw_data(path):
data = list()
with open(path) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=",")
for r in csv_reader:
if (r[1] != "Time Stamp"):
data.append( (r[1], r[2]) )
return data
def save_rps_totals(totals, path):
with open(path, mode="w") as result:
wtr = csv.writer(result)
for k, v in totals.items():
wtr.writerow([k,v])
def save_rps_above_threshold(readings, path):
with open(path, mode="w", newline='') as result:
wtr = csv.writer(result)
for item in readings:
wtr.writerow([item])
def save_filtered_flickers(readings, path):
with open(path, mode="w") as results:
wtr = csv.writer(results)
for item in readings:
wtr.writerow(item)

16
src/services/log_services.py

@ -0,0 +1,16 @@
def print_dictionary(dictionary):
for k,v in dictionary.items():
print(f"{k} : {v}")
def print_list(the_list):
for item in the_list:
print(f"{item}")
def update(message):
print(f"[UPDATE] {message}")
def error(message):
print(f"[ERROR] {message}")
def info(message):
print(f"[INFO] {message}")