Coder Social home page Coder Social logo

What does this code do? about mycodo HOT 11 CLOSED

kizniche avatar kizniche commented on August 24, 2024
What does this code do?

from mycodo.

Comments (11)

kizniche avatar kizniche commented on August 24, 2024

Heh... This may not be efficient at all, but it works. I am storing the variables for each conditional statement (may be multiple) for each sensor (may be multiple).

Directly after initializing the array, the arrays are set:
Lines 3116 though 3156.

Then on lines 768 and beyond it will check if the value is not 0 to determine if there is a conditional.

Why there is a range of 10, I'm not sure. This was a tricky section for me to get working and I believe I haven't put much more thought into it after I found the first working solution.

from mycodo.

kizniche avatar kizniche commented on August 24, 2024

Initialized to 0s based on how many conditional statements created for each sensor (line 3076):

    cur.execute('SELECT id FROM tsensor')
    for row in cur:
        conditional_t_number_sensor.append(row[0])

    cur.execute('SELECT id FROM tsensorconditional')
    for row in cur:
        conditional_t_number_conditional.append(row[0])

    conditional_t_id = [[[0 for k in xrange(10)] for j in xrange(len(conditional_t_number_conditional))] for i in xrange(len(conditional_t_number_sensor))]

Set from 0 to value in SQLite DB (line 3134):

        for row in cur:
            conditional_t_id[j][count][0] = row[0]

Then check if != 0 (line 768):

        #
        # Check if T conditional statements are true
        #
        for j in range(0, len(conditional_t_number_sensor)):
            for k in range(0, len(conditional_t_number_conditional)):
                if conditional_t_id[j][k][0] != 0 and client_que != 'TerminateServer' and pause_daemon != 1 and PID_change != 1:

from mycodo.

kizniche avatar kizniche commented on August 24, 2024

Aha! I think I used 10 because at the time I was unsure how to define the proper length. I figured 10 would be enough conditional statements for each sensor and I would come back and fix this later. I actually am unsure what I was thinking and I'm still a little unsure how the code works, but I managed to get it working.

from mycodo.

Cabalist avatar Cabalist commented on August 24, 2024

Gotcha. Everybody has code like that sometimes. 😆

I rewrote some of this. You will need to test to make sure that it creates the same values you are expecting but I don't anticipate that it is any different.

from mycodo.

kizniche avatar kizniche commented on August 24, 2024

Thanks for the help. If you can assist me in understanding a little bit... Is what I'm trying to accomplish achieved by changing:
conditional_t_id = get_3d_array(10, len(conditional_t_number_conditional), len(conditional_t_number_sensor))
to
conditional_t_id = get_3d_array(len(conditional_t_number_sensor), len(conditional_t_number_conditional), 1)
Initial tests seem to work... Still testing, though.

from mycodo.

kizniche avatar kizniche commented on August 24, 2024

I'm fairly sure that did it. Because I'm only setting the first element of the third list, this needs to be 1?
The array is initialized with:
conditional_t_id = get_3d_array(len(conditional_t_number_sensor), len(conditional_t_number_conditional), 1)
Then the last element is set with:
conditional_t_id[j][count][0] = row[0]

from mycodo.

kizniche avatar kizniche commented on August 24, 2024

Nope. List out of range error when multiple sensors is use.

from mycodo.

kizniche avatar kizniche commented on August 24, 2024

Aha. After some rudimentary testing, I found that I was misinterpreting how I was declaring the 3d array. I was understanding it backwards. The following is the correct way to declare the array:
conditional_t_id = get_3d_array(1, len(conditional_t_number_conditional), len(conditional_t_number_sensor))
If I want to read it like:
conditional_t_id[sensor_number][conditional_number][0]
Fixed in fe583e9

from mycodo.

kizniche avatar kizniche commented on August 24, 2024

Perhaps x, y, and z of get_3d_array() should be reversed, to enhance readability.

from mycodo.

Cabalist avatar Cabalist commented on August 24, 2024

X Y and Z are arbitrary. I purposefully didn't put any of the sensor logic
into that function. It might be worthwhile to put some notes before the
blocks of initialization to say what you are using it for there. :)

On Mon, Nov 23, 2015 at 1:41 AM, Kyle Gabriel [email protected]
wrote:

Perhaps x, y, and z of get_3d_array() should be reversed, to enhance
readability.


Reply to this email directly or view it on GitHub
#52 (comment).

from mycodo.

kizniche avatar kizniche commented on August 24, 2024

Good idea. I'll add some comments.

I was meaning with reversing x y, and z for readability, so the order of the function parameters is the same order as the array indexes. For instance, currently this is how the function and array is used:

conditional_array = get_3d_array(1, number_conditionals, number_sensors)
conditional_array[number of sensors][number of conditionals][0] = True

But if x, y, and z are reversed, it appears as:

conditional_array = get_3d_array(number_sensors, number_conditionals, 1)
conditional_array[number of sensors][number of conditionals][0] = True

from mycodo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.