Have ideas to improve npm?Join in the discussion! »

    contest-compiler

    1.1.4 • Public • Published

    Getting Started With Contest Compiler

    Install & Use

      npm install contest-compiler

    (may you tell me how you use it? so i can make this more dynamic...)

    Usage (My Scenario)

    1. Used for Dynamic Contest Scoring System
    • The Logic :

      A. Five A Judge, 1 B Judge and 2 Penalty Types

      B. Calculation:

      i. X = Find the 3 A Judge's Score that is closest to medium and take the average

      ii. Score = 10 - X + B Judge - 2 Penalty

    • Annoying Stuff if you need to Code this in different Scenario

    • With A UI Including Below Funtions, this module can let user configure the contest scoring logic in 1 minutes. Easy right?

    • The Origin intension: Let the User Code~

    • Store the Code inside database (i used mongoDB) and I can do the scoring based on this compiler with different type of scores.

    Compiler Logic

    1. (OPERATOR VALUE VALUE VALUE VALUE ...)
    2. Each Value can be: Operator with Value / Value / Variable
    • e.g: (OPERATOR (OPERATOR VALUE VALUE) (OPERATOR (OPERATOR VALUE VALUE) VALUE))
    1. The Inner Operation will execute FIRST
    2. The Outer Operation will only get the value of the inner operation

    Masking

    1. Value can be masked as Variable before execute. This can be used for storing.
    • You can always alter the stored code for a new scoring algorithm.
    • You don't need to program the algorithm again, just change that code (string).
    1. You need to Pass a (Key & Array) in JSON Object before Execute.
    • e.g :
      • Stored Code: (+ {D} 10) = (D + 10)
      • Use the Matcher Function in Masking
      • Input : Data = { D : [3] }
      • Matcher(Data, Stored Code)
      • Execute (3 + 10)

    Rounding

      var copmiler = require('contest-compiler');
      /**
       * 1. Compiler Code
       * 2. Debug (Boolean)
       * 3. Rounding Type (TRIM / ROUND_UP / ROUND_DOWN)
       * 4. precision
       */
      var result = compiler.exec(code, true, compiler.utils.Roundings.TRIM, 3);

    Operators

      • / - / * / /
    • Normal Operation with Two / Above Element
    • Code: (+ 4 5 6 (- 3 4) (* 2 3)) = 4+5+6+(3-4)+(2*3)
    1. MAX / MID / MIN
    • Find the value that is the Maximum / Closest to Medium / Minimum / Count the Total Element
    • Code: (MAX (+3 4) 5 6)
    • Operation: (+3 4) = 7 => Find The Max. of : [ 7, 5, 6 ] => Return 7
    1. CNT
    • Find the Total Element (Count)
    • Code: (CNT 1 1 2 1 2 1 2) => return 7
    1. MEDIAN
    • Find the Median
    • Code: (MEDIAN (CNT 1 1 1) (MAX 3 4 5))
    • Operation: (CNT 1 1 1) return 3 =>(MAX 3 4 5) return 5 => (MEDIAN 3 5) return 4
    1. AVG
    • Find the Average
    • Code: (AVG 3 4 5)
    • Operation: (3+4+5) / 3 = 4
    1. HIGH / LOW
    • Find the Highest / LOWEST X Array
    • First Number will be the X (Total of Highest / Lowest Value)
    • Code: (HIGH 3 4 5 6 7 8)
    • Operation: Get Highest 3 Value => (4 5 6 7 8) return (8 7 6)

    Examples

    1. Validate Compiler Code (Boolean Function)
    var Mask = require('contest-compiler').masking;
    var code = "(AVG 3 4 {D})";
    var validation = Mask.validate(code); // Return True / False
    1. Masking Value to Variable and return Compiler Codec (String Function)
    var Mask = require('contest-compiler').masking;
    var code = "(AVG 3 4 {D} {E} {E} {E} {E})";
    var data = { D: [3], E: [1, 2, 3, -6] };
    // Code Result => (AVG 3 4 3 1 2 3 -6)
    var real_code = Mask.match(data, code);
    // Return "(AVG 3 4 3 1 2 3 -6)"

    P.S : null will be return if Invalid Data or Data Length

    1. Compile with Masked Function (Integer / Array Function)
    var compiler = require('contest-compiler');
    var Mask = require('contest-compiler').masking;
    var code = "(AVG 3 4 {D} {E} {E} {E} {E})";
    var data = { D: [3], E: [1, 2, 3, -6] };
    // Code Result => (AVG 3 4 3 1 2 3 -6)
    var real_code = Mask.match(data, code);
    // Return "(AVG 3 4 3 1 2 3 -6)"
    var result = compiler.exec(real_code);
    // Return Average of : [3, 4, 3, 1, 2, 3, -6] = 1.42...
    var fixed_result = compiler.exec(real_code, 2);
    // Take The Decimal Place to 2 : 1.42857... => 1.43
    1. Get Variables in String
    • This would be useful when you only store the string in database and want to compile with incoming values
    var Mask = require('contest-compiler').masking;
    var code = "(AVG 3 4 {D} {E} {E} {E} {E})";
    var variables = Mask.getVariable(code);
    // Return { "D": 1, "E": 3 }

    Install

    npm i contest-compiler

    DownloadsWeekly Downloads

    1

    Version

    1.1.4

    License

    MIT

    Unpacked Size

    17.3 kB

    Total Files

    10

    Last publish

    Collaborators

    • avatar