diff --git a/WikiRating/WebContent/WEB-INF/classes/log4j.properties b/WikiRating/WebContent/WEB-INF/classes/log4j.properties new file mode 100644 index 0000000..b288681 --- /dev/null +++ b/WikiRating/WebContent/WEB-INF/classes/log4j.properties @@ -0,0 +1,9 @@ +# Root logger option +log4j.rootLogger=DEBUG, stdout, file + +# Redirect log messages to console +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n + diff --git a/WikiRating/pom.xml b/WikiRating/pom.xml index 083c209..15dca97 100644 --- a/WikiRating/pom.xml +++ b/WikiRating/pom.xml @@ -1,90 +1,99 @@ 4.0.0 WikiRating WikiRating 0.0.1-SNAPSHOT war src maven-compiler-plugin 3.3 1.7 1.7 maven-war-plugin 2.6 WebContent false org.wikidata.wdtk wdtk-wikibaseapi 0.6.0 + + log4j + log4j + 1.2.17 + + + + + org.glassfish.main.extras glassfish-embedded-all 4.0 provided com.tinkerpop.blueprints blueprints-core 2.6.0 com.fasterxml.jackson.core jackson-databind 2.6.3 net.sourceforge jwbf 3.1.0 com.orientechnologies orientdb-jdbc 2.1.16 asm asm 3.3.1 com.sun.jersey jersey-bundle 1.19 org.json json 20140107 com.sun.jersey jersey-server 1.19 com.sun.jersey jersey-core 1.19 \ No newline at end of file diff --git a/WikiRating/src/main/java/computations/BadgeGenerator.java b/WikiRating/src/main/java/computations/BadgeGenerator.java index 45d46ab..057df18 100644 --- a/WikiRating/src/main/java/computations/BadgeGenerator.java +++ b/WikiRating/src/main/java/computations/BadgeGenerator.java @@ -1,184 +1,187 @@ package main.java.computations; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.impls.orient.OrientGraph; import main.java.utilities.Connections; +import main.java.utilities.Logs; import main.java.utilities.PropertiesAccess; /** * This class will calculate the Badges that will be assigned * to the Pages based on the analysis of Page Rating distribution */ public class BadgeGenerator { + Class className=BadgeGenerator.class; //These variables will store the computed cutoffs for the various badges static double platinumBadgeRatingCutoff; static double goldBadgeRatingCutoff; static double silverBadgeRatingCutoff; static double bronzeBadgeRatingCutoff; static double stoneBadgeRatingCutoff; /** * This ENUM has the percentile ranges for various badges */ public enum Badges { PLATINUM(1), GOLD(2), SILVER(3), BRONZE(4), STONE(5), PLATINUM_BADGE_START_PERCENTILE(80), GOLD_BADGE_START_PERCENTILE(60), SILVER_BADGE_START_PERCENTILE(40), BRONZE_BADGE_START_PERCENTILE(20), STONE_BADGE_START_PERCENTILE(0); private int value; Badges(int value) { this.value = value; } public int getValue() { return value; } } /** * This class will store our PageObjects to insert into ArrayList for * percentile calculations */ public class PageRatingData{ int pid; double pageRating; String pageName; public PageRatingData(int pid,double pageRating,String pageName) { this.pid=pid; this.pageRating=pageRating; this.pageName=pageName; } } /** * This is the custom comparator to sort the pageList in the ascending * order of PageRatings */ class PageRatingComparator implements Comparator{ @Override public int compare(PageRatingData pageRating1, PageRatingData pageRating2) { if(pageRating1.pageRating>pageRating2.pageRating) return 1; else return -1; } } /** * This method will assign badges based on the percentile */ public void generateBadges(){ ArrayList pageList=new ArrayList(); OrientGraph graph = Connections.getInstance().getDbGraph(); Vertex currentPageNode=null; int badgeNumber=4; int currentPageID=0,noOfPages=0; double currentPageRating=0,maxPageRating=0; String currentPageName=""; for(Vertex pageNode:graph.getVertices("@class","Page")){ currentPageID=pageNode.getProperty("pid"); currentPageRating=pageNode.getProperty("PageRating"); currentPageName=pageNode.getProperty("title"); pageList.add(new PageRatingData(currentPageID, currentPageRating,currentPageName)); } Collections.sort(pageList,new PageRatingComparator()); calculateBadgeCutoff(pageList); noOfPages=pageList.size(); int noOfPagesCounter=0; for(PageRatingData currentPage:pageList){ badgeNumber=getBadgeNumber(currentPage.pageRating); + Logs.getLogs(className).info(currentPage.pageName + " ------with ratings= "+currentPage.pageRating+" earned "+badgeNumber); System.out.println(currentPage.pageName + " ------with ratings= "+currentPage.pageRating+" earned "+badgeNumber); currentPageNode=graph.getVertices("pid",currentPage.pid).iterator().next(); currentPageNode.setProperty("badgeNumber",badgeNumber); graph.commit(); noOfPagesCounter++; if(noOfPagesCounter==noOfPages) maxPageRating=currentPage.pageRating; } //Adding the max value to the Preferences for later access PropertiesAccess.putParameter("maxRating", maxPageRating); graph.shutdown(); } /** * This method will calculate the cutoff for the various badges * @param pageList The ArrayList containing Page Objects */ public static void calculateBadgeCutoff(ArrayList pageList){ int noOfPages=pageList.size(); int platinumPageIndex; int goldPageIndex; int silverPageIndex; int bronzePageIndex; int stonePageIndex; //Storing index where the cutoff of badges start to get the respective cutoffs platinumPageIndex=(int)(noOfPages*(Badges.PLATINUM_BADGE_START_PERCENTILE.value/100.00)); goldPageIndex=(int)(noOfPages*(Badges.GOLD_BADGE_START_PERCENTILE.value/100.00)); silverPageIndex=(int)(noOfPages*(Badges.SILVER_BADGE_START_PERCENTILE.value/100.00)); bronzePageIndex=(int)(noOfPages*(Badges.BRONZE_BADGE_START_PERCENTILE.value/100.00)); stonePageIndex=(int)(noOfPages*(Badges.STONE_BADGE_START_PERCENTILE.value/100.00)); //Storing cutoffs platinumBadgeRatingCutoff=pageList.get(platinumPageIndex).pageRating; goldBadgeRatingCutoff=pageList.get(goldPageIndex).pageRating; silverBadgeRatingCutoff=pageList.get(silverPageIndex).pageRating; bronzeBadgeRatingCutoff=pageList.get(bronzePageIndex).pageRating; stoneBadgeRatingCutoff=pageList.get(stonePageIndex).pageRating; System.out.println("Index "+platinumPageIndex+"marks platinum cutoff -------"+platinumBadgeRatingCutoff); System.out.println("Index "+goldPageIndex+"marks gold cutoff------"+goldBadgeRatingCutoff); System.out.println("Index "+silverPageIndex+"marks silver cutoff------"+silverBadgeRatingCutoff); System.out.println("Index "+bronzePageIndex+"marks bronze cutoff------"+bronzeBadgeRatingCutoff); System.out.println("Index "+stonePageIndex+"marks stone cutoff------"+stoneBadgeRatingCutoff); } /** * This method will pick the badge according to the passed pageRating * @param pageRating PageRating of the page under consideration * @return The name of the Badge earned */ public static int getBadgeNumber(double pageRating){ if(pageRating>=platinumBadgeRatingCutoff) return Badges.PLATINUM.value; else if(pageRating>=goldBadgeRatingCutoff) return Badges.GOLD.value; else if(pageRating>=silverBadgeRatingCutoff) return Badges.SILVER.value; else if(pageRating>=bronzeBadgeRatingCutoff) return Badges.BRONZE.value; else return Badges.STONE.value; } } diff --git a/WikiRating/src/main/java/computations/PageRating.java b/WikiRating/src/main/java/computations/PageRating.java index d867cbc..b293074 100644 --- a/WikiRating/src/main/java/computations/PageRating.java +++ b/WikiRating/src/main/java/computations/PageRating.java @@ -1,37 +1,39 @@ package main.java.computations; import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.impls.orient.OrientGraph; import main.java.utilities.Connections; +import main.java.utilities.Logs; import main.java.utilities.PropertiesAccess; /** * This class will compute the final Page rating combining all the parameter in the Master Equation */ public class PageRating{ final static double PAGERANK_IMPORTANCE_PARAMETER=Double.parseDouble(PropertiesAccess.getParameterProperties("PAGERANK_IMPORTANCE_PARAMETER")); /** * This method combines all the parameters are calculate and store the final Page Rating of the Page. * @return void */ public static void computePageRatings(){ + double currentPageReliability=0,pageRank=0,currentPageVote=0,pageRating=0; OrientGraph graph = Connections.getInstance().getDbGraph(); for(Vertex pageNode:graph.getVertices("@class","Page")){ try{ currentPageReliability=pageNode.getProperty("currentPageReliability"); pageRank=pageNode.getProperty("Pagerank"); currentPageVote=pageNode.getProperty("currentPageVote"); pageRating=((currentPageReliability*currentPageVote)+(PAGERANK_IMPORTANCE_PARAMETER*pageRank)); pageNode.setProperty("PageRating", pageRating); System.out.println(pageNode.getProperty("title")+" ======has rating==== "+pageRating); }catch(Exception e){e.printStackTrace();} } graph.commit(); graph.shutdown(); } } diff --git a/WikiRating/src/main/java/utilities/Logs.java b/WikiRating/src/main/java/utilities/Logs.java new file mode 100644 index 0000000..0324820 --- /dev/null +++ b/WikiRating/src/main/java/utilities/Logs.java @@ -0,0 +1,23 @@ +package main.java.utilities; + +import org.apache.log4j.Logger; + +import main.java.computations.PageRating; + + +public class Logs { + + +/** + * This method returns a logger object for the passes classname + * @param className + * @return + */ +public static Logger getLogs(Class className){ + //Logs.getLogs(className).info("This is a log message from Page"); + final Logger logger = Logger.getLogger(className); + return logger; + +} + +}