fklang icon indicating copy to clipboard operation
fklang copied to clipboard

Computation ext

Open phodal opened this issue 2 years ago • 0 comments

Feature Request

Is your feature request related to a problem? Please describe. add simple math support for fklang

Describe the solution you'd like like: https://github.com/MetaBorgCube/IceDust

module students

model

  entity Student {
    name       : String
    
    passedCourses : Int = sum(enrollments.pass2)
  }
  
  entity Course {
    name       : String
    
    avgGrade   : Float?  = avg(enrollments.grade)
    passPerc   : Float?  = sum(enrollments.pass2) / count(enrollments) * 100.0
    numStudents: Int     = count(enrollments)
  }
  
  entity Enrollment {
    name       : String  = course.name + " " +student.name
    
    grade      : Float?
    pass       : Boolean = grade >= 5.5 <+ false
    pass2      : Int     = pass ? 1 : 0
  }
  
  relation Course.enrollments *  <-> 1 Enrollment.course
  relation Student.enrollments * <-> 1 Enrollment.student

data

  alice : Student {
    name = "Alice"
  }
  bob : Student {
    name = "Bob"
  }
  charlie : Student {
    name = "Charlie"
  }
  math : Course {
    name = "Math"
    enrollments = 
      enA {
        student = alice
        grade = 8.0
      },
      enB {
        student = bob
        grade = 9.5
      },
      enC {
        student = charlie
        grade = 5.0
      }
  }
  
execute

  math.name
  math.avgGrade
  math.passPerc
  math.numStudents

phodal avatar Nov 05 '22 02:11 phodal