Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* CLASE DE UTILIDAD PARA CALCULAR RANKINGs DE DESAFÍOS CODEEVAL.
- * Juan José Guerra - dinertron@gmail.com - 2014 */
- /**
- * * <cite><small>FROM 'CODEEVAL' (<a
- * href="https://www.codeeval.com/ranking/">https
- * ://www.codeeval.com/ranking/</a>)</small></cite><br />
- * <small><b>LANGUAGE</b>: Spanish<small> <h1>CALCULO DEL RECORD EN EL RANKING</h1>
- * <p>
- * Es una clase MUY SIMPLE (y MEJORABLE) que utilizo para calcular el record
- * conseguido en un desafío de los propuestos en CODEEVAL, con propósitos
- * estadísticos y de archivación.<br />
- * No está finalizada al completo (faltaría MANEJO DE ERRORES, DEPURACIÓN, ...)
- * pero de momento me basta para hacerme una idea del Ranking de cada desafío.
- * </p>
- * <p style="background:lightGray;">
- * UTILIZACIÓN: ver javadoc {@link #main(String...)} para los parámetros
- * ejecutables.
- * </p>
- *
- * @author guerraTron - dinertron@gmail.com - 2014
- **/
- public abstract class RankingScore {
- /*
- * # if submission takes more than 10 seconds # or uses more than 20MB of
- * memory # the score is 0
- */
- static final int MAX_MEMORY = 20 * 1024 * 1024; // 20 MB
- static final int MAX_TIME = 10 * 1000; // 10 sec
- /**
- * @param args
- * : (String[]) donde:
- * <ul>
- * <li>args[0] : <b>SCORE</b> : la puntuación recibida por los
- * tests (the score which is received by test-cases).</li>
- * <li>args[1] : <b>MEMORY-TAKEN</b> : memoria ocupada por el
- * codigo empleado (memory taken by submission).</li>
- * <li>args[2] : <b>TIME-TAKEN</b> : tiempo que ha tomado el
- * codigo empleado (time taken by submission).</li>
- * <li>args[3] : <b>CATEGORY</b> :
- * FACIL-Easy(1)/MEDIO-Moderate(2)/DIFICIL-Hard(3).</li>
- * </ul>
- **/
- public static void main(String... args) {
- if (args.length == 0) {
- System.out.println("WITHOUT ARGUMENTS -SIN ARGUMENTOS-");
- // System.exit(-1);
- return;
- }
- float memoryFactor = get_memory_factor(Long.parseLong(args[1]),
- MAX_MEMORY);
- float timeFactor = get_time_factor(Long.parseLong(args[2]), MAX_TIME);
- System.out.println("MEMORY FACTOR -FACTOR DE MEMORIA- : "
- + memoryFactor);
- System.out.println("TIME FACTOR -FACTOR DE TIEMPO- : " + timeFactor);
- System.out.println("TOTAL FACTOR -FACTOR TOTAL- : "
- + get_total_factor(memoryFactor, timeFactor));
- System.out.println("TOTAL SCORE -PUNTUACION TOTAL- : "
- + get_submission_score(Float.parseFloat(args[0]),
- Long.parseLong(args[1]), Long.parseLong(args[2]),
- Byte.parseByte(args[3])));
- }
- /**
- * Formula utilizada para calcular La Puntuacion (SCORE) a utilizar para el
- * RANKING.
- *
- * @param score
- * : la puntuación recibida por los tests (the score which is
- * received by test-cases)
- * @param memory_taken
- * : memoria ocupada por el codigo empleado (memory taken by
- * submission)
- * @param time_taken
- * : tiempo que ha tomado el codigo empleado (time taken by
- * submission)
- * @param category
- * : FACIL-Easy(1)/MEDIO-Moderate(2)/DIFICIL-Hard(3)
- **/
- public static float get_submission_score(float score, long memory_taken,
- long time_taken, byte category) {
- int[] total_max = new int[] { 0, // NO UTILIZADO
- 35, // max 35 points for Easy challenge
- 65, // max 65 points for Moderate challenge
- 100 // max 100 points for Hard challenge
- };
- /*
- * # if submission takes more than 10 seconds # or uses more than 20MB
- * of memory # the score is 0
- */
- if (memory_taken > MAX_MEMORY || time_taken > MAX_TIME)
- return 0;
- int max_total_score = total_max[category];
- float memory_factor = get_memory_factor(memory_taken, MAX_MEMORY);
- float time_factor = get_time_factor(time_taken, MAX_TIME);
- float factor = get_total_factor(memory_factor, time_factor);
- return score * max_total_score * factor / 100;
- }
- /**
- * Formula utilizada para calcular el FACTOR DE MEMORIA a utilizar para la
- * formula del RANKING.<br />
- * Esto se emplea en el calculo de la formula mediante el metodo
- * {@link #get_submission_score(float,long,long,byte)}
- *
- * @param memory_taken
- * : memoria ocupada por el codigo empleado (memory taken by
- * submission)
- * @param max_memory
- * : memoria maxima permitida
- **/
- public static float get_memory_factor(long memory_taken, long max_memory) {
- /*
- * # if submission takes more than 10 seconds # or uses more than 20MB
- * of memory # the score is 0
- */
- if (memory_taken > max_memory)
- return 0;
- return (1 - ((float) memory_taken / max_memory));
- }
- /**
- * Formula utilizada para calcular el FACTOR DE TIEMPO a utilizar para la
- * formula del RANKING.<br />
- * Esto se emplea en el calculo de la formula mediante el metodo
- * {@link #get_submission_score(float,long,long,byte)}
- *
- * @param time_taken
- * : tiempo que ha tomado el codigo empleado (time taken by
- * submission)
- * @param max_time
- * : tiempo maximo permitido
- **/
- public static float get_time_factor(long time_taken, long max_time) {
- /*
- * # if submission takes more than 10 seconds # or uses more than 20MB
- * of memory # the score is 0
- */
- if (time_taken > max_time)
- return 0;
- return (1 - ((float) time_taken / max_time));
- }
- /**
- * Formula utilizada para calcular el FACTOR TOTAL (DE MEMORIA Y TIEMPO) a
- * utilizar para la formula del RANKING.<br />
- * Esto se emplea en el calculo de la formula mediante el metodo
- * {@link #get_submission_score(float,long,long,byte)}
- *
- * @param memory_factor
- * : factor de memoria ocupada por el codigo empleado
- * @param time_factor
- * : factor de tiempo que ha tomado el codigo empleado
- **/
- public static float get_total_factor(float memory_factor, float time_factor) {
- return ((memory_factor + time_factor) / 2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement