<commit_before><?php
header ( 'Content-Type: text/html; charset=utf-8' );
date_default_timezone_set ( 'Europe/Berlin' );
include ('config.php');
include ('functions.php');
$err_level = error_reporting ( 0 );
$my = new mysqli ( $my_host, $my_user, $my_pass );
error_reporting ( $err_level );
if ($my->connect_error)
	die ( "Datenbankverbindung nicht möglich." );
$my->set_charset ( 'utf8' );
$my->select_db ( $my_name );

$pgr = pg_connect ( $pgr_connectstr );
if(!$pgr)
	die ( "Datenbankverbindung (PostgreSQL) nicht möglich." . pg_last_error () );

if( isset($_GET["newtrack"])
		&& ($_GET['newtrack'] == "newtrack")
		&& isset($_GET['user_token'])
		&& isset($_GET['length'])
		&& isset($_GET['duration'])
		&& isset($_GET['name'])
		&& isset($_GET['comment'])
		&& (isset($_GET['data']) || isset($_POST['data'])) ) {
	
	// user_token passed by the app.
	$user_token = $my->real_escape_string ( $_GET ['user_token'] );
	if (verify_token ( $user_token, $my )) {
		// Create new unique track_id
		// uniqid() generates a 23-character unique string with the giver prefix (ibis_)
		$track_id = uniqid ( "tra_", true );
		
		// Created UNIX-timestamp
		$created = time ();
		
		// Länge (in Metern) des Tracks
		$length = intval($my->real_escape_string ( $_GET ['length'] ));
		
		// Dauer (in Sekunden) des Tracks
		$duration = intval($my->real_escape_string ( $_GET ['duration'] ));
		
		// Name (vom User festgelegt) des Tracks; max. 49 chars
		$name = substr ( $my->real_escape_string ( $_GET ['name'] ), 0, 48 );
		
		// Beschreibung (vom User festgelegt) des Tracks; max. 249 chars
		$comment = substr ( $my->real_escape_string ( $_GET ['comment'] ), 0, 248 );
		
		// Public: Track is public availible (anonymous)
		if(isset($_GET ['public']))
			if($_GET ['public'] == "true")
				$public = 1;
			else
				$public = 0;
		else
			$public = 1;
		
		$track_string = "";
		
		// data: json-encoded user track
		// array of (lat, lon, alt, time, speed, additional-info (not used so far))
		$nodes = 0;
		if(isset($_POST['data'])) {
			$data_raw = $_POST['data'];
		} else {
			$data_raw = $_GET['data'];
		}
		$data = json_decode($data_raw, true, 3);
		if(count($data)>=1){
			foreach ($data as $element) {
				if(isset($element["lat"]) && isset($element["lon"]) && isset($element["tst"])){
					$time = intval($element["tst"]); 	// UNIX timestamp ist ganzzahlig
					$lat = floatval($element["lat"]); 	// lat, lon und alt sind Gleitkommazahlen
					$lon = floatval($element["lon"]);
					if(isset($element["alt"])) {
						$alt = floatval($element["alt"]);
					} else {
						$alt = "NULL";
					}
					if(isset($element["spe"])) {
						$spe = floatval($element["spe"]);
					} else {
						$spe = "NULL";
					}
					// Länge (in Metern) des Tracks
					if($element["acc"]) {
						$acc = floatval($element["acc"]);
					} else {
						$acc = 0;
					}
					$query = "INSERT INTO rawdata_server_php (lat, lon, alt, time, speed, track_id, the_geom)
					VALUES (" . $lat . ",  " . $lon . ",  " . $alt . ", " . $time . ", " . $spe . ", '" . $track_id . "', ST_SetSRID(ST_MakePoint(".$lon.",".$lat."),4326))";
					$result = pg_query ( $query );
					if ( $result ) {
						pg_free_result ( $result );
						$nodes++;
						$track_string .= $time.$lat.$lon;
					}
					// Effizenz? Evtl alle Querys sammeln und gemeinsam ausführen?
				}
			}
			
			// Generate hash of track: $track_string
			
			$hash = sha1($track_string);
			
			$my->query ( "INSERT INTO `ibis_server-php`.`tracks` (`user_token`, `track_id`, `created`, `length`, `duration`, `nodes`, `name`, `comment`, `public`, `hash`, `data_raw`, `acc`)
			VALUES ('" . $user_token . "', '" . $track_id . "',  '" . $created . "',  '" . $length . "',  '" . $duration . "',    '" . $nodes . "',  '" . $name . "', '" . $comment . "', '" . $public . "', '" . $hash . "', '" . $my->real_escape_string($data_raw) . "', '".$acc."')" );<commit_msg>bugfix: corrected track upload (insert accuracy into PgSQL db)<commit_after><?php
header ( 'Content-Type: text/html; charset=utf-8' );
date_default_timezone_set ( 'Europe/Berlin' );
include ('config.php');
include ('functions.php');
$err_level = error_reporting ( 0 );
$my = new mysqli ( $my_host, $my_user, $my_pass );
error_reporting ( $err_level );
if ($my->connect_error)
	die ( "Datenbankverbindung nicht möglich." );
$my->set_charset ( 'utf8' );
$my->select_db ( $my_name );

$pgr = pg_connect ( $pgr_connectstr );
if(!$pgr)
	die ( "Datenbankverbindung (PostgreSQL) nicht möglich." . pg_last_error () );

if( isset($_GET["newtrack"])
		&& ($_GET['newtrack'] == "newtrack")
		&& isset($_GET['user_token'])
		&& isset($_GET['length'])
		&& isset($_GET['duration'])
		&& isset($_GET['name'])
		&& isset($_GET['comment'])
		&& (isset($_GET['data']) || isset($_POST['data'])) ) {
	
	// user_token passed by the app.
	$user_token = $my->real_escape_string ( $_GET ['user_token'] );
	if (verify_token ( $user_token, $my )) {
		// Create new unique track_id
		// uniqid() generates a 23-character unique string with the giver prefix (ibis_)
		$track_id = uniqid ( "tra_", true );
		
		// Created UNIX-timestamp
		$created = time ();
		
		// Länge (in Metern) des Tracks
		$length = intval($my->real_escape_string ( $_GET ['length'] ));
		
		// Dauer (in Sekunden) des Tracks
		$duration = intval($my->real_escape_string ( $_GET ['duration'] ));
		
		// Name (vom User festgelegt) des Tracks; max. 49 chars
		$name = substr ( $my->real_escape_string ( $_GET ['name'] ), 0, 48 );
		
		// Beschreibung (vom User festgelegt) des Tracks; max. 249 chars
		$comment = substr ( $my->real_escape_string ( $_GET ['comment'] ), 0, 248 );
		
		// Public: Track is public availible (anonymous)
		if(isset($_GET ['public']))
			if($_GET ['public'] == "true")
				$public = 1;
			else
				$public = 0;
		else
			$public = 1;
		
		$track_string = "";
		
		// data: json-encoded user track
		// array of (lat, lon, alt, time, speed, additional-info (not used so far))
		$nodes = 0;
		if(isset($_POST['data'])) {
			$data_raw = $_POST['data'];
		} else {
			$data_raw = $_GET['data'];
		}
		$data = json_decode($data_raw, true, 3);
		if(count($data)>=1){
			foreach ($data as $element) {
				if(isset($element["lat"]) && isset($element["lon"]) && isset($element["tst"])){
					$time = intval($element["tst"]); 	// UNIX timestamp ist ganzzahlig
					$lat = floatval($element["lat"]); 	// lat, lon und alt sind Gleitkommazahlen
					$lon = floatval($element["lon"]);
					if(isset($element["alt"])) {
						$alt = floatval($element["alt"]);
					} else {
						$alt = "NULL";
					}
					if(isset($element["spe"])) {
						$spe = floatval($element["spe"]);
					} else {
						$spe = "NULL";
					}
					// Länge (in Metern) des Tracks
					if($element["acc"]) {
						$acc = floatval($element["acc"]);
					} else {
						$acc = 0;
					}
					$query = "INSERT INTO rawdata_server_php (lat, lon, alt, time, speed, track_id, the_geom, acc)
					VALUES (" . $lat . ",  " . $lon . ",  " . $alt . ", " . $time . ", " . $spe . ", '" . $track_id . "', ST_SetSRID(ST_MakePoint(".$lon.",".$lat."),4326), '".$acc."')";
					$result = pg_query ( $query );
					if ( $result ) {
						pg_free_result ( $result );
						$nodes++;
						$track_string .= $time.$lat.$lon;
					}
					// Effizenz? Evtl alle Querys sammeln und gemeinsam ausführen?
				}
			}
			
			// Generate hash of track: $track_string
			
			$hash = sha1($track_string);
			
			$my->query ( "INSERT INTO `ibis_server-php`.`tracks` (`user_token`, `track_id`, `created`, `length`, `duration`, `nodes`, `name`, `comment`, `public`, `hash`, `data_raw`)
			VALUES ('" . $user_token . "', '" . $track_id . "',  '" . $created . "',  '" . $length . "',  '" . $duration . "',    '" . $nodes . "',  '" . $name . "', '" . $comment . "', '" . $public . "', '" . $hash . "', '" . $my->real_escape_string($data_raw) . "')" );
{'fraction_non_alphanumeric': 0.21473174461577674, 'fraction_numerical': 0.007391359755320505, 'mean_word_length': 3.208042895442359, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '65911', 'n_tokens_mistral': 3302, 'n_tokens_neox': 2822, 'n_words': 622}