-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dec 20 tele fix #49
Merged
Merged
dec 20 tele fix #49
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
304447d
WIP
valaises 6e6104e
Changelist:
valaises e14517e
rh: human bugfix
valaises e68bcdb
small fix
valaises f5b0701
robot human fixes
valaises 1cef7e9
TELEMETRY_TRANSMIT_EACH_N_SECONDS = 3600
valaises d0c9967
negative robot human workaround
valaises 1aebc50
changes requested by @olegklimov
valaises f176cfe
minor
valaises 225b3c9
implemented kirill's suggestions
valaises 79ffb95
added debug level to _tracing
valaises de27b8a
minor
valaises 7b0f50e
small fix
valaises 1921420
removed extra arg from get_add_del_from_texts
valaises File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
use std::collections::HashMap; | ||
use tracing::{error, info}; | ||
use std::sync::Arc; | ||
use tracing::{debug, error, info}; | ||
use std::sync::{Arc, RwLockWriteGuard}; | ||
use std::sync::RwLock as StdRwLock; | ||
use std::path::PathBuf; | ||
use regex::Regex; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::json; | ||
use regex::Regex; | ||
|
||
use tokio::sync::RwLock as ARwLock; | ||
|
||
|
@@ -15,7 +15,51 @@ use crate::telemetry::telemetry_structs; | |
use crate::telemetry::telemetry_structs::{SnippetTracker, TeleRobotHumanAccum}; | ||
|
||
|
||
const ROBOT_HUMAN_FILE_STATS_UPDATE_EVERY: i64 = 15; | ||
|
||
pub fn create_robot_human_record_if_not_exists( | ||
tele_robot_human: &mut Vec<TeleRobotHumanAccum>, | ||
uri: &String, | ||
text: &String | ||
) { | ||
let record_mb = tele_robot_human.iter_mut().find(|stat| stat.uri.eq(uri)); | ||
if record_mb.is_some() { | ||
return; | ||
} | ||
info!("create_robot_human_rec_if_not_exists: new uri {}", uri); | ||
let record = TeleRobotHumanAccum::new( | ||
uri.clone(), | ||
text.clone(), | ||
); | ||
tele_robot_human.push(record); | ||
} | ||
|
||
|
||
fn update_robot_characters_baseline( | ||
rec: &mut TeleRobotHumanAccum, | ||
snip: &SnippetTracker | ||
) { | ||
let re = Regex::new(r"\s+").unwrap(); | ||
let robot_characters = re.replace_all(&snip.grey_text, "").len() as i64; | ||
rec.robot_characters_acc_baseline += robot_characters; | ||
} | ||
|
||
fn basetext_to_text_leap_calculations( | ||
rec: &mut TeleRobotHumanAccum, | ||
baseline_text: String, | ||
text: &String, | ||
) { | ||
let re = Regex::new(r"\s+").unwrap(); | ||
let (added_characters, removed_characters) = utils::get_add_del_from_texts(&baseline_text, text); | ||
|
||
let (added_characters, _) = utils::get_add_del_chars_from_texts(&removed_characters, &added_characters); | ||
|
||
// let real_characters_added = re.replace_all(&added_characters, "").len() as i64 - re.replace_all(&removed_characters, "").len() as i64; | ||
let human_characters = re.replace_all(&added_characters, "").len() as i64 - rec.robot_characters_acc_baseline; | ||
debug!("human_characters: +{}; robot_characters: +{}", human_characters, rec.robot_characters_acc_baseline); | ||
rec.human_characters += human_characters; | ||
rec.robot_characters += rec.robot_characters_acc_baseline; | ||
rec.robot_characters_acc_baseline = 0; | ||
} | ||
valaises marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
pub fn increase_counters_from_finished_snippet( | ||
|
@@ -24,67 +68,40 @@ pub fn increase_counters_from_finished_snippet( | |
text: &String, | ||
snip: &SnippetTracker, | ||
) { | ||
// Snippet is finished when it stops being valid for correction (user has changed code in a different place) or it timeouts | ||
fn robot_characters(snip: &SnippetTracker) -> i64 { | ||
let re = Regex::new(r"\s+").unwrap(); | ||
let robot_characters = re.replace_all(&snip.grey_text, "").len() as i64; | ||
info!("increase_counters_from_finished_snippet: ID: {}; robot_characters: {}", snip.snippet_telemetry_id, robot_characters); | ||
robot_characters | ||
} | ||
fn human_characters(rec: &TeleRobotHumanAccum, text: &String) -> i64 { | ||
let re = Regex::new(r"\s+").unwrap(); | ||
let (added_characters, _) = utils::get_add_del_from_texts(&rec.baseline_text, text); | ||
let human_characters = re.replace_all(&added_characters, "").len() as i64 - rec.robot_characters_acc_baseline; | ||
human_characters | ||
} | ||
|
||
info!("snip grey_text: {}", snip.grey_text); | ||
let now = chrono::Local::now().timestamp(); | ||
|
||
if let Some(rec) = tele_robot_human.iter_mut().find(|stat| stat.uri.eq(uri)) { | ||
if rec.used_snip_ids.contains(&snip.snippet_telemetry_id) { | ||
return; | ||
} | ||
let robot_characters = robot_characters(snip); | ||
rec.robot_characters_acc_baseline += robot_characters; | ||
rec.used_snip_ids.push(snip.snippet_telemetry_id); | ||
if rec.baseline_updated_ts + ROBOT_HUMAN_FILE_STATS_UPDATE_EVERY < now { | ||
// New baseline, increase counters | ||
rec.baseline_updated_ts = now; | ||
rec.human_characters += human_characters(rec, text); | ||
rec.robot_characters += rec.robot_characters_acc_baseline; | ||
rec.robot_characters_acc_baseline = 0; | ||
rec.baseline_text = text.clone(); | ||
} | ||
info!("increasing for {}, human+{}, robot+{}", snip.snippet_telemetry_id, human_characters(rec, text), robot_characters); | ||
} else { | ||
info!("increase_counters_from_finished_snippet: new uri {}", uri); | ||
let init_file_text_mb = snip.inputs.sources.get(&snip.inputs.cursor.file); | ||
if init_file_text_mb.is_none() { | ||
return; | ||
|
||
if rec.used_snip_ids.is_empty() { | ||
rec.model = snip.model.clone(); | ||
} | ||
let init_file_text = init_file_text_mb.unwrap(); | ||
tele_robot_human.push(TeleRobotHumanAccum::new( | ||
uri.clone(), | ||
snip.model.clone(), | ||
init_file_text.clone(), | ||
robot_characters(snip), | ||
vec![snip.snippet_telemetry_id], | ||
)); | ||
|
||
update_robot_characters_baseline(rec, snip); | ||
basetext_to_text_leap_calculations(rec, rec.baseline_text.clone(), text); | ||
|
||
rec.used_snip_ids.push(snip.snippet_telemetry_id); | ||
rec.baseline_updated_ts = now; | ||
rec.baseline_text = text.clone(); | ||
} | ||
} | ||
|
||
fn compress_robot_human( | ||
data: &mut Vec<TeleRobotHumanAccum> | ||
storage_locked: &mut RwLockWriteGuard<telemetry_structs::Storage> | ||
) -> Vec<TeleRobotHuman> { | ||
let mut unique_combinations: HashMap<(String, String), Vec<&TeleRobotHumanAccum>> = HashMap::new(); | ||
let mut unique_combinations: HashMap<(String, String), Vec<TeleRobotHumanAccum>> = HashMap::new(); | ||
|
||
let tele_robot_human = storage_locked.tele_robot_human.clone(); | ||
|
||
for accum in data { | ||
for accum in tele_robot_human { | ||
let key = (accum.file_extension.clone(), accum.model.clone()); | ||
unique_combinations.entry(key).or_default().push(accum); | ||
} | ||
let mut compressed_vec= vec![]; | ||
for (key, entries) in unique_combinations { | ||
info!("compress_robot_human: compressing {} entries for key {:?}", entries.len(), key); | ||
// info!("compress_robot_human: compressing {} entries for key {:?}", entries.len(), key); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same with debug! |
||
let mut record = TeleRobotHuman::new( | ||
key.0.clone(), | ||
key.1.clone() | ||
|
@@ -114,7 +131,10 @@ pub async fn tele_robot_human_compress_to_file( | |
enduser_client_version = cx_locked.cmdline.enduser_client_version.clone(); | ||
|
||
let mut storage_locked = storage.write().unwrap(); | ||
for rec in compress_robot_human(&mut storage_locked.tele_robot_human) { | ||
for rec in compress_robot_human(&mut storage_locked) { | ||
if rec.model.is_empty() && rec.robot_characters == 0 && rec.human_characters == 0 { | ||
continue; | ||
} | ||
let json_dict = serde_json::to_value(rec).unwrap(); | ||
records.as_array_mut().unwrap().push(json_dict); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove extra comments