MCPcopy Create free account
hub / github.com/OWASP/SecurityShepherd / getJsonScore

Method getJsonScore

src/main/java/dbProcs/Getter.java:820–972  ·  view source on GitHub ↗

Use to return the current progress of a class in JSON format with information like userid, user name and score @param applicationRoot The current running context of the application @param classId The identifier of the class to use in lookup @return A JSON representation of a class's score in the ord

(String applicationRoot, String classId)

Source from the content-addressed store, hash-verified

818 * goldmedalcount, goldDisplay, silverMedalCount, silverDisplay, bronzeDisplay, bronzeMedalCount}
819 */
820 @SuppressWarnings("unchecked")
821 public static String getJsonScore(String applicationRoot, String classId)
822 {
823 log.debug("classId: " + classId);
824 String result = new String();
825 Connection conn = Database.getCoreConnection(applicationRoot);
826 try
827 {
828 //Returns User's: Name, # of Completed modules and Score
829 CallableStatement callstmnt = null;
830 if(ScoreboardStatus.getScoreboardClass().isEmpty() && !ScoreboardStatus.isClassSpecificScoreboard())
831 callstmnt = conn.prepareCall("call totalScoreboard()"); //Open Scoreboard not based on a class
832 else
833 {
834 callstmnt = conn.prepareCall("call classScoreboard(?)"); //Class Scoreboard based on classId
835 callstmnt.setString(1, classId);
836 }
837 //log.debug("Executing classScoreboard");
838 ResultSet resultSet = callstmnt.executeQuery();
839 JSONArray json = new JSONArray();
840 JSONObject jsonInner = new JSONObject();
841 int resultAmount = 0;
842 int prevPlace = 0;
843 int prevScore = 0;
844 int prevGold = 0;
845 int prevSilver = 0;
846 int prevBronze = 0;
847 float baseBarScale = 0; //
848 float tieBreaker = 0;
849 while(resultSet.next()) //For each user in a class
850 {
851 resultAmount++;
852 jsonInner = new JSONObject();
853 if(resultSet.getString(1) != null)
854 {
855 int place = resultAmount;
856 int score = resultSet.getInt(3);
857 int goldMedals = resultSet.getInt(4);
858 int silverMedals = resultSet.getInt(5);
859 int bronzeMedals = resultSet.getInt(6);
860 if(resultAmount == 1) //First Place is Returned First, so this will be the biggest bar on the scoreboard
861 {
862 int highscore = score;
863 //log.debug("Current Highscore Listing is " + highscore);
864 //Use the high score to scale the width of the bars for the whole scoreboard
865 float maxBarScale = 1.02f; //High Score bar will have a scale of 1 //This will get used when a scale is added to the scoreboard
866 baseBarScale = highscore * maxBarScale;
867 //setting up variables for Tie Scenario Placings
868 prevPlace = 1;
869 prevScore = score;
870 }
871 else
872 {
873 //Does this score line match the one before (Score and Medals)? if so the place shouldnt change
874 if (score == prevScore && goldMedals == prevGold && silverMedals == prevSilver && bronzeMedals == prevBronze)
875 {
876 place = prevPlace;
877 tieBreaker = tieBreaker + 0.01f;

Calls 4

getCoreConnectionMethod · 0.95
getScoreboardClassMethod · 0.95
closeConnectionMethod · 0.95