<commit_before>import java.io.*;
import java.util.*;
import java.text.*;
import javax.servlet.*;
import javax.servlet.http.*;
import imcode.external.diverse.*;
import imcode.util.*;

/**
 * @author  <NAME>
 * @version 1.0
 * Date : 2001-09-05
 */

public class QuestionResult extends HttpServlet 
{
	String resultTemplate = "QuestionResult.htm";
		
	
	public void doGet(HttpServletRequest req, HttpServletResponse res)
	throws ServletException, IOException 
	{
		String host = req.getHeader("Host") ;
		String imcServer = Utility.getDomainPref("userserver",host) ;
		File fortune_path = Utility.getDomainPrefPath("fortune_path",host);
		
		//get answer
		String answer = req.getParameter("answer");
		
		//get question
		String question = req.getParameter("question");
		String fileName = question;

		String row = req.getParameter("quesrow") ;
		try {
		    fileName = "QuestionResult"+Integer.parseInt(row) ;
		} catch ( NumberFormatException ignored ) {
		    /* The question is used as filename */
		}

		//g igenom strngen tecken fr tecken och byt ut allt utom '_', siffror och bokstver till '_'.
		for(int i = 0;i<fileName.length(); i++)
		{
			char c = fileName.charAt(i);
			if (!Character.isJavaIdentifierPart(c))
			{
				fileName=fileName.replace(c,'_');
			}
		}
		
		//get current answers from file
		int yes = 0;
		int no = 0;

		File file = new File(fortune_path,fileName.trim() + ".txt");
		if (file.exists())
		{
		    try {
			BufferedReader fileR = new BufferedReader(new FileReader(file));
			
			fileR.skip(3);
			String y = fileR.readLine();
			yes = Integer.parseInt(y.trim());
			
			fileR.skip(4);
			String n = fileR.readLine();
			no = Integer.parseInt(n.trim());
		
			fileR.close();
		    } catch (IOException ignored) {
			// yes = 0, no = 0
		    } catch (NumberFormatException ignored) {
			// yes = 0, no = 0
		    } catch (NullPointerException ignored) {
			// yes = 0, no = 0
		    } 

		}
	
		//save the answer to the file
		BufferedWriter fileW = new BufferedWriter( new FileWriter(file) );
		
		if (Integer.parseInt(answer)==1) {yes++;} else {no++;}
		
		fileW.write("ja: " + yes,0,(Integer.toString(yes)).length()+4);
		fileW.newLine();
		fileW.write("nej: " + no,0,Integer.toString(no).length()+5);
		fileW.newLine();
		fileW.flush();
		fileW.close();
		
		//get the total number of answers
		int total = yes+no;
		
		//get the %
		double yesDiv = (yes==0) ? 0 : ((double)yes/(double)total);
		double noDiv = (no==0) ? 0 : ((double)no/(double)total);
		
		NumberFormat pf = NumberFormat.getPercentInstance();
		pf.setMaximumFractionDigits(0);
		
		String yesProcent = pf.format(yesDiv);
		String noProcent = pf.format(noDiv);
		
		//Add info for parsing to a Vector and parse it with a template to a htmlString that is printed
		Vector values = new Vector();
		values.add("#question#");
		values.add(question);
		values.add("#yesProcent#");
		values.add(yesProcent);
		values.add("#noProcent#");
		values.add(noProcent);
		values.add("#total#");
		values.add(Integer.toString(total));
		
		String parsed = IMCServiceRMI.parseExternalDoc(imcServer, values, resultTemplate , "se", "106");
		
		res.setContentType("text/html");
		PrintWriter out = res.getWriter();
		out.println(parsed);
		
		return ;


	} // End doGet

	

	public void doPost(HttpServletRequest req, HttpServletResponse res)
	throws ServletException, IOException 
	{
		doGet(req,res);
		return ;
	}	

} // End class


<commit_msg>bug 122 new servlet<commit_after>import java.io.*;
import java.util.*;
import java.text.*;
import javax.servlet.*;
import javax.servlet.http.*;
import imcode.external.diverse.*;
import imcode.util.*;

/**
 * @author  <NAME>
 * @version 1.0
 * Date : 2001-09-05
 */

public class QuestionResult extends HttpServlet 
{
	String resultTemplate = "QuestionResult.htm";
		
	
	public void doGet(HttpServletRequest req, HttpServletResponse res)
	throws ServletException, IOException 
	{
		String host = req.getHeader("Host");
		String imcServer = Utility.getDomainPref("userserver",host);
		String fortune_path = Utility.getDomainPref("fortune_path",host);
		
		//get answer
		String file = req.getParameter("file");
		String answer = req.getParameter("answer");
		
		//gets the filecontent 
		String resFile = IMCServiceRMI.getFortune(imcServer,file + "current.txt");
		StringTokenizer tokens = new StringTokenizer(resFile,"#");
		
		String date1 = tokens.nextToken();
		String date2 = tokens.nextToken();

		String question = tokens.nextToken();
		
		int yes = Integer.parseInt( ( (tokens.nextToken() ).substring(3) ).trim() );
		int no = Integer.parseInt( ( (tokens.nextToken() ).substring(4) ).trim() );

		//save the answer to the file
		if (Integer.parseInt(answer)==1) 
		{
			yes = yes + 1;
			//++yes;
		} 
		else 
		{
			no = no + 1;
			//++no;
		}
	
		String newFileContent =date1 + "#" + date2 + "#" + question + "#ja: " + yes + "#nej: " + no + "#";
	
		BufferedWriter fileW = new BufferedWriter( new FileWriter(fortune_path + file + "current.txt" ) );
		fileW.write(newFileContent);
		fileW.flush();
		fileW.close();
		
		//get the total number of answers
		int total = yes+no;
		
		//get the %
		double yesDiv = (yes==0) ? 0 : ((double)yes/(double)total);
		double noDiv = (no==0) ? 0 : ((double)no/(double)total);
		
		NumberFormat pf = NumberFormat.getPercentInstance();
		pf.setMaximumFractionDigits(0);
		
		String yesProcent = pf.format(yesDiv);
		String noProcent = pf.format(noDiv);
		
		//Add info for parsing to a Vector and parse it with a template to a htmlString that is printed
		Vector values = new Vector();
		values.add("#question#");
		values.add(question);
		values.add("#yesProcent#");
		values.add(yesProcent);
		values.add("#noProcent#");
		values.add(noProcent);
		values.add("#total#");
		values.add(Integer.toString(total));
		
		
		String parsed = IMCServiceRMI.parseExternalDoc(imcServer, values, resultTemplate , "se", "106");
		
		res.setContentType("text/html");
		PrintWriter out = res.getWriter();
		out.println(parsed);
		
		return ;

	} // End doGet

	

	public void doPost(HttpServletRequest req, HttpServletResponse res)
	throws ServletException, IOException 
	{
		doGet(req,res);
		return ;
	}
	
} // End class



{'fraction_non_alphanumeric': 0.1481421647819063, 'fraction_numerical': 0.010339256865912763, 'mean_word_length': 3.6029739776951675, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3193917', 'n_tokens_mistral': 2320, 'n_tokens_neox': 2004, 'n_words': 488}