Nonviolent Pirate Mobster

npm

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

contest-compiler

1.1.4 • Public • Published

Install & Use

(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

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)

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)
1. Masking Value to Variable and return Compiler Codec (String Function)

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

1. Compile with Masked Function (Integer / Array Function)
1. Get Variables in String
• This would be useful when you only store the string in database and want to compile with incoming values

Keywords

Install

`npm i contest-compiler`

1

1.1.4

MIT

17.3 kB

10