You are on page 1of 3

package com.

evaluation;
import
import
import
import
import

java.sql.DriverManager;
java.sql.ResultSet;
java.sql.SQLException;
java.sql.Statement;
java.util.ArrayList;

import com.mysql.jdbc.Connection;
public class CalculatePrecision {
//mitchell
/**
* @param args
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws ClassNotFoundException, SQ
LException {
ArrayList<String> session_id=new ArrayList<>();
String dbUrl = "jdbc:mysql://localhost:3306/preprocessing";
String dbUrl1 = "jdbc:mysql://localhost:3306/evaluation";
Class.forName("com.mysql.jdbc.Driver");
Connection connection=(Connection) DriverManager.getConnection(d
bUrl, "root", "");
//
Connection condburl1=(Connection) DriverManager.getConnection(db
Url1, "root", "");
Connection con=(Connection) DriverManager.getConnection("jdbc:my
sql://localhost:3306/track", "root", "");
Connection con1=(Connection) DriverManager.getConnection("jdbc:m
ysql://localhost:3306/track", "root", "");
String query="select distinct(session_id) from recommendation_co
unt LIMIT 6";
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(query);
while(rs.next()){
session_id.add(rs.getString(1));
}
for(int i=0;i<session_id.size();i++){
int tot_pages=0;
int rec_pages=0;
int rec_rel_pages=0;
int rel_pages_wdout_recommendation=0;
int total_rel_pages=0;
int irrelevant_recommended_pages=0;
float precision=0,recall=0,fallout=0,miss_rate=0;
String query1="select count(distinct(url)) from tracking
where session_id like '"+session_id.get(i)+"'";
//
System.out.println(query1);
Statement stmt1=con1.createStatement();
ResultSet rs1=stmt1.executeQuery(query1);
while(rs1.next()){
tot_pages=rs1.getInt(1);
System.out.println("Total pages visited:"+tot_pages);
}
String query2="select count(distinct(url)) from recommen
dation_values where session_id like'"+session_id.get(i)+"'";
//
System.out.println(query2);
Statement stmt2=con.createStatement();
ResultSet rs2=stmt2.executeQuery(query2);

while(rs2.next()){
rec_pages=rs2.getInt(1);
System.out.println("total pages recommended:"+rec_pages);
}
String query3="select count(distinct(url)) from user_rec
ommendations where session_id like '"+session_id.get(i)+"'";
//
System.out.println(query3);
Statement stmt3=con.createStatement();
ResultSet rs3=stmt3.executeQuery(query3);
while(rs3.next()){
rec_rel_pages=rs3.getInt(1);
System.out.println("recommended pages visited:"+
rec_rel_pages);
}
//
String query4="SELECT count(tracking.url) FROM tracking
LEFT JOIN user_recommendation ON tracking.session_id = user_recommendation.sessi
on_id WHERE tracking.session_id like '"+session_id.get(i)+"' and user_recommenda
tion.session_id like '"+session_id.get(i)+"'";
String query4="select count(distinct(url)) from tracking
where session_id='"+session_id.get(i)+"' and url not in (select url from recomm
endation_values where session_id='"+session_id.get(i)+"')";
Statement stmt4=con.createStatement();
ResultSet rs4=stmt.executeQuery(query4);
while(rs4.next()){
rel_pages_wdout_recommendation=rs4.getInt(1);
System.out.println("not recommended but visited:
"+rel_pages_wdout_recommendation);
}
String query5="select count(distinct(url)) from recommen
dation_values where session_id='"+session_id.get(i)+"' and url not in(select url
from user_recommendations where session_id='"+session_id.get(i)+"')";
Statement stmt5=con.createStatement();
ResultSet rs5=stmt5.executeQuery(query5);
while(rs5.next()){
irrelevant_recommended_pages=rs5.getInt(1);
}
System.out.println("recommended but not visited:"+irrele
vant_recommended_pages);
// new chnges
/*String query7="select count(distinct(url)) from tracki
ng where session_id like '"+session_id.get(i)+"'";
Statement stmt7=con1.createStatement();
ResultSet rs7=stmt7.executeQuery(query7);
while(rs7.next()){
total_rel_pages=rs7.getInt(1);
System.out.println("tot rel pages:"+total_rel_pages); //
used distinct pgs
}*/
int tot_irrelevant=450-tot_pages;
System.out.println("tot_irrelevant:"+tot_irrelevant);
precision=(float)((float)rec_rel_pages/(float)rec_pages)
;
recall=(float)((float)rec_rel_pages/(float)tot_pages);
fallout=(float)((float)(irrelevant_recommended_pages)/(f
loat)(tot_irrelevant));
miss_rate=(float)((float)(rel_pages_wdout_recommendation

)/(float)(tot_pages));
System.out.println("precision :"+precision);
System.out.println("recall :"+recall);
System.out.println("fallout :"+fallout);
System.out.println("MissRate:"+miss_rate);
//
Statement stmt5=condburl1.createStatement();
String ins_query="insert into eval_param values('"+preci
sion+"','"+recall+"','"+fallout+"','"+miss_rate+"')";
//
int rs5=stmt5.executeUpdate(ins_query);
}
}
}