<commit_before>package db;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;

import coordinates.Coordinate;
import coordinates.CoordinateDetermination;
import db.tuples.BubbleTuple;
import gui.SplashController;

/**
 * @author <NAME>
 * 
 * Class for pre-processing data in your database.
 */
public class DatabaseProcessor {
	private Statement db;
	private DatabaseReader dbr;
	private int noOfSegments;
	
	public DatabaseProcessor(Statement db, DatabaseReader dbr) {
		this.db = db;
		this.dbr = dbr;
	}
	
	/**
	 * Calculating the coordinates of segments and store them in the database
	 */
	public void updateCoordinates() {
		
		CoordinateDetermination coorddet = new CoordinateDetermination(dbr);
		Coordinate[] coordinates = coorddet.calcCoords();
		SplashController.progressString.set("Saving segment coordinates");
		for (int i = 1; i <= coordinates.length; i++) {
			if ( (i % coordinates.length) / 10 == 0) {
				SplashController.progressString
					.set((i * 100 / coordinates.length) + "% Stored");
			}
			try {
				this.db.executeUpdate("UPDATE SEGMENTS SET "
						+ "XCOORD = " + coordinates[i - 1].getX() 
						+ ", YCOORD = " + coordinates[i - 1].getY()
						+ " WHERE ID = " + i);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	
	/**
	 * Identifies the innermost bubbles (without inner bubbles) and inserts the
	 * start and end segment id of each bubble that is found into the 'BUBBLES'
	 * table.
	 */
	public void locateBubbles() {

		ArrayList<ArrayList<Integer>> links = dbr.getLinks();
		for (int segmentId = 1; segmentId <= links.size(); segmentId++) {
			ArrayList<Integer> outgoingEdges = links.get(segmentId - 1);
			
			if (outgoingEdges.size() > 1) {
				int firstChildId = outgoingEdges.get(0);
				int secondChildId = outgoingEdges.get(1);
				ArrayList<Integer> firstChildEdges = links.get(firstChildId - 1);
				ArrayList<Integer> secondChildEdges = links.get(secondChildId - 1);
				
				int firstChildEdge;
				int secondChildEdge;
				try {
					firstChildEdge = firstChildEdges.get(0);
					secondChildEdge = secondChildEdges.get(0);
				} catch (IndexOutOfBoundsException e) {
					System.err.println("Index out of bounds, skipping segment: " + segmentId);
					break;
				}
				if (secondChildEdge == firstChildEdge || firstChildId == secondChildEdge
						|| secondChildId == firstChildEdge) {
					try {
						this.db.executeUpdate(new BubbleTuple(segmentId, firstChildEdge)<commit_msg>Removed indel from bubble detection<commit_after>package db;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;

import coordinates.Coordinate;
import coordinates.CoordinateDetermination;
import db.tuples.BubbleTuple;
import gui.SplashController;

/**
 * @author <NAME>
 * 
 * Class for pre-processing data in your database.
 */
public class DatabaseProcessor {
	private Statement db;
	private DatabaseReader dbr;
	private int noOfSegments;
	
	public DatabaseProcessor(Statement db, DatabaseReader dbr) {
		this.db = db;
		this.dbr = dbr;
	}
	
	/**
	 * Calculating the coordinates of segments and store them in the database
	 */
	public void updateCoordinates() {
		
		CoordinateDetermination coorddet = new CoordinateDetermination(dbr);
		Coordinate[] coordinates = coorddet.calcCoords();
		SplashController.progressString.set("Saving segment coordinates");
		for (int i = 1; i <= coordinates.length; i++) {
			if ( (i % coordinates.length) / 10 == 0) {
				SplashController.progressString
					.set((i * 100 / coordinates.length) + "% Stored");
			}
			try {
				this.db.executeUpdate("UPDATE SEGMENTS SET "
						+ "XCOORD = " + coordinates[i - 1].getX() 
						+ ", YCOORD = " + coordinates[i - 1].getY()
						+ " WHERE ID = " + i);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	
	/**
	 * Identifies the innermost bubbles (without inner bubbles) and inserts the
	 * start and end segment id of each bubble that is found into the 'BUBBLES'
	 * table.
	 */
	public void locateBubbles() {

		ArrayList<ArrayList<Integer>> links = dbr.getLinks();
		for (int segmentId = 1; segmentId <= links.size(); segmentId++) {
			ArrayList<Integer> outgoingEdges = links.get(segmentId - 1);
			
			if (outgoingEdges.size() > 1) {
				int firstChildId = outgoingEdges.get(0);
				int secondChildId = outgoingEdges.get(1);
				ArrayList<Integer> firstChildEdges = links.get(firstChildId - 1);
				ArrayList<Integer> secondChildEdges = links.get(secondChildId - 1);
				
				int firstChildEdge;
				int secondChildEdge;
				try {
					firstChildEdge = firstChildEdges.get(0);
					secondChildEdge = secondChildEdges.get(0);
				} catch (IndexOutOfBoundsException e) {
					System.out.println("Skipping segment: " + segmentId);
					break;
				}
				if (secondChildEdge == firstChildEdge) {
					try {
						this.db.executeUpdate(new BubbleTuple(segmentId, firstChildEdge)
{'fraction_non_alphanumeric': 0.11559193451786784, 'fraction_numerical': 0.007187063286085047, 'mean_word_length': 3.651810584958217, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, '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': '3939835', 'n_tokens_mistral': 1831, 'n_tokens_neox': 1510, 'n_words': 391}