Skip to main content
Question

Cross Product

  • July 31, 2018
  • 0 replies
  • 148 views

This is something that I have a fairly good understanding of in other database tools such as Sql, but do not know if Quickbase could handle.

I am trying to create a training application that allows for records to be created of employees attending training. All of these trainings require Test Scores and Attendance. Some of these trainings are done in Groups. For Example:

Training                              Group                     Employee

T1 G1                                 G1                         E1
T2 G1                                 G2                         E2
T3 G1                                 G3
T4 G2
T5 G2
T6 G3

I would like to be able to select a list of employees and a single group and then have a cross product of each training and employee be created, so that attendance and scores can be recorded.

Group = G1
Employeee = E1 , E2

Result
G1*E1 = ( (T1 , E1 ) , ( T2 , E1 ) , (T3 , E1)  
G1*E2 =  (T1 , E2 ) ( T2 , E2 ) , (T3 , E2)


Without this, the best way that I can think to record this is the embed a report where a record is created for each employee and training in the group individually. Is these a better way to create these records?

Thanks.
This topic has been closed for replies.

  • Registered
  • August 2, 2018
This can easily be done with script. However, I don't understand the structure of your tables or where you want the cross product data to show up.

Nevertheless, here is some sample code that will create the cross product of two arrays ["T1", "T2", "T3"] _ ["E1", "E2"]

function crossProductOf() {
  return _.reduce(arguments, function(a, b) {
    return _.flatten(_.map(a, function(x) {
      return _.map(b, function(y) {
        return x.concat();
      });
    }), true);
  }, [ [] ]);
};
var array1 = ["T1", "T2", "T3"];
var array2 = ["E1", "E2"];
var crossProduct = crossProductOf(array1, array2); 
console.log(JSON.stringify(crossProduct, null, "  "));

output:
[
  ["T1","E1"],
  ["T1","E2"],
  ["T2","E1"],
  ["T2","E2"],
  ["T3","E1"],
  ["T3","E2"]
]
To implement this you need to use script to obtain the data for each array using API_DoQuery and then call the above code and either pump the cross product into a table or spit out the results as HTML. 

MATH TRIVIA: Did you know that the cross product or Cartesian product is named after the famous mathematician Ren� Descarte?

                                           

There may also be a native solution but it�s unclear to me if you are wanting to do a mathematical calculation and what your data structure is for parent and child relationships.

  • Registered
  • August 10, 2018
Even though the heavy hitters have responded to this I am going to take a swing at a native solution.
I would have a 4 table solution
Table 1  - Training
Table 2 - Groups
Table 3 - Employees
Table 4 - Test Scores

The Trainer can create the training, then create groups and select the employees in the groups and keep the scores. The scores table could be designed to keep not just the score of each employee test but what group and training session.
This structure would allow the evaluations of employees, groups, and trainers from the scoring I am , however, assuming that when you want to get such detail the goal is not to only evaluate the employees but the trainings as well. How else could you know when group size is having a direct affect on scores?
You will need some automation and a few buttons based on the details of the hows of your training structure. 

As always Dan is right anything can be done in scripting. If you want me to explain more about my response feel free to contact me.