Suneido

Integrated Application Platform

  • Home
  • Learning
    • Suneido Manual
    • Beginners
      • Inside Suneido
      • The Suneido Programming Language
      • The Suneido Database
      • Installing Suneido
      • Building Suneido
      • IDE Go To Tour
      • Upgrading To A New Release
    • Advanced
      • Canvas Control
      • DrawControl Part 1
      • DrawControl Part 2
      • DrawControl Part 3
      • SAX Like XML Processing
      • A Plug-In Architecture
      • A Simple Wizard Framework
      • An HTML Include Facility
      • An RSS 2 Feed Creator
      • MIME Generation
      • A New Add-on Facility
      • Workspace Improvement Hack
    • Mockito for Suneido
    • The Suneido Task Scheduler
    • Contributing To Suneido
    • Contributor Assignment of Copyright
    • Language Translation
    • Future Directions
    • Interview With Andrew Mckinlay
  • Forum
    • Announcements
    • Internals & Enhancements
    • Cookbook
    • General
  • FAQ
  • Screenshots
  • Downloads
  • Links

counting based on more than two members of an object from inside a loop

Integrated Application Platform › Forums › General › counting based on more than two members of an object from inside a loop

  • This topic has 4 replies, 2 voices, and was last updated 7 years, 11 months ago by ajith.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • February 10, 2015 at 3:55 am #1148
    ajith
    Participant

    Hi,

    1) I need to construct a loop that goes through an object that conatins object. The child objects all have the same members. In the first cycle, the loop needs to check each member of the child objects and get a count of the child objects that have the value true. Based on this, a score is calculated and in the second loop I need to count the number of child objects that have two members (selected by the previous cycle) with value true. These cycles repeat a number of times. Each time, the number of members based on which I need the count increases by 1.

    I do not know how to specify how to count based on two members inside the loop. If I was using a query, I could have appended to the “where” of the query. How do I do something equivalent to objects?

    The line of code that does the count the first cycle is
    ob.pst += ((row[test1] is true) ? 1:0
    In the next cycle,in its place I need do something equiavalent to
    ob.pst += ((row[test1] is true and row[test2] is true) ? 1:0
    2) Is that possible? If not, is there a way to convert an object of objects to a database table other than outputting one record by one from inside a loop?

    Thanks,
    ajith

    February 13, 2015 at 7:39 am #1150
    amckinlay
    Keymaster

    I am not sure exactly what you are looking for.

    Your lines of code look valid (except you have extra opening parenthesis)

    You could use the “functional” methods like object.Filter and object.Count or the combined object.CountIf

    e.g. n = rows.CountIf({ it[test1] is true and it[test2] is true })

    There is no shortcut to output a list of objects to a database table. It would be easy to write something that used a loop. If you have the data in memory it will be faster to process it there.

    I hope that helps.

    February 13, 2015 at 11:53 am #1151
    ajith
    Participant

    Hi Andrew,

    Thanks for the reply. It appears that I did not state my problem clearly:

    The two (and more) lines of codes needs to be generated inside a loop.
    The first cycle should generate the first line of code, the second cycle of the loop should generate the second. In the next loop the line of code generated should count based on three columns and so on.

    If I write manually, the code will work (of course, after ensuring the correct pair of brackets and braces). I can’t write manually, it needs to be generated inside the loop as the number of loops is variable each time I use the code.

    The other way that I can think of is to output the objects into a database table and build the “where” query.

    Is it possible the first way? Or is there another way?

    Thanks,
    ajith

    February 14, 2015 at 8:29 am #1152
    amckinlay
    Keymaster

    You could build the code the same way you would build the query where and then use string.Eval. You would need to write it as a function and pass in the arguments. But that should not be necessary.

    If you make a list of the field names then you can just loop through them.

    function (row, fields)
        {
        for f in fields
            if row[f] isnt true
                return false
        return true
        }

    The first time the list would just have one field, the second time two fields, etc.

    Is that more what you are looking for?

    February 15, 2015 at 10:49 pm #1153
    ajith
    Participant

    Hi,

    Thanks for the reply.

    Yes, I think what I was looking for was string.Eval().

    I will try the way that you have suggested and come back if there is any doubts.

    Thanks
    ajith

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Log In

Search Forums

Log In
Welcome to the new Suneido Web Site and Forum.
Register
Lost Password
users of the previous PHPBB Forum should be able to log in with their previous username and password.

Recent Topics

  • Alpha copy of gSuneido to play with
  • how to start jsuneido ?
  • Problem Starting Suneido…
  • Dialog not showing buttons
  • New link for Suneidojo

Contact Us | Legal Statement | Privacy Statement | SiteMap

Copyright © 2023 Axon® Development Corporation. All Rights Reserved. - Open Source Integrated Database and Programming Language