<commit_before>open History
open Wire

type counter = Cstruct.uint64 [@printer fun fmt -> fprintf fmt "0x%Lx"]
[@@deriving show]


type physical_parameters = {
    skm_scale:      float;
    ts_limit:       float;
    skm_rate:       float;
    e_offset:       float;
    e_offset_qual:  float;
    initial_p:     (float * float);
    shift_thres:    counter;
}
[@@deriving show]


type windows    = {
    toplevel:           (point * point);

    warmup:             (point * point);

    shift_detection:    (point * point);
    offset:             (point * point);

    plocal_far:         (point * point);
    plocal_near:        (point * point);

}
[@@deriving show]

let default_windows =
    let history_scale = 3600 * 24 * 7 in
    let warmup_samples = 480 in
    let poll_period = 16 in
    let shift_win = 100 in
    let top_win_size = history_scale / poll_period in

    let toplevel          = (Newest, Older(Newest, top_win_size     - 1)) in
    let shift_detection   = (Newest, Older(Newest, shift_win        - 1)) in
    let warmup            = (Newest, Older(Newest, warmup_samples   - 1)) in
    {warmup}



let default_parameters =
    let skm_scale       = 1024.0 in
    let ts_limit        = 1.5e-5 in
    let skm_rate        = 2e-7 in
    let e_offset        = 6.0 *. ts_limit in (* 6 = offset_ratio *)
    let e_offset_qual   = 3.0 *. e_offset in
    let initial_p       = (1e-9, 0.0) in
    let shift_thres     = 0L in
    {skm_scale; ts_limit; skm_rate; e_offset; e_offset_qual; initial_p; shift_thres}

let delta_TSC newer older =
    let del = Int64.sub newer older in
    match (del >= 0L) with
    | true  -> del
    | false -> failwith "invalid ΔTSC!"

type nonce = {
    tsc:    counter;    (* the TSC value when we send it *)
    txts:   ts;         (* the random number that was in the transmit_timestamp of the packet we sent *)
}

type timestamps = {
    ta:     counter;
    tb:     float               [@printer fun fmt -> fprintf fmt "%.09f"];
    te:     float               [@printer fun fmt -> fprintf fmt "%.09f"];<commit_msg>get the plocal windows correct<commit_after>open History
open Wire

type counter = Cstruct.uint64 [@printer fun fmt -> fprintf fmt "0x%Lx"]
[@@deriving show]


type physical_parameters = {
    skm_scale:      float;
    ts_limit:       float;
    skm_rate:       float;
    e_offset:       float;
    e_offset_qual:  float;
    initial_p:     (float * float);
    shift_thres:    counter;
}
[@@deriving show]


type windows    = {
    toplevel:           (point * point);

    warmup:             (point * point);

    shift_detection:    (point * point);
    offset:             (point * point);

    plocal_far:         (point * point);
    plocal_near:        (point * point);

}
[@@deriving show]

let default_windows params =
    let history_scale = 3600 * 24 * 7 in        (* seconds *)
    let poll_period = 16 in                     (* seconds per sample *)

    let warmup_samples  = 480 in                (* everything below measured in terms of samples *)
    let top_win_size    =               history_scale       / poll_period in
    let offset_size     = (int_of_float params.skm_scale)   / poll_period in
    let shift_win       = 100 in

    let toplevel            = (Newest, Older(Newest, top_win_size   - 1)) in
    let shift_detection     = (Newest, Older(Newest, shift_win      - 1)) in
    let warmup              = (Newest, Older(Newest, warmup_samples - 1)) in

    (* plocal stuff:
        * wwidth is the width of each of the plocal_far / plocal_near windows
        * plocal_span is *how far apart* those windows are from each other
    *)

    let plocal_span = 5 * offset_size   in
    let wwidth      = plocal_span / 5   in

    let plocal_near         = (Newest, Older(Newest, wwidth         - 1)) in

    let plocal_far_centre   = Older(Newest, plocal_span         ) in
    let plocal_far          = (Older(plocal_far_centre, wwidth/2), Older(plocal_far_centre, wwidth + wwidth/2 - 1)) in

    {warmup}

let default_parameters =
    let skm_scale       = 1024.0 in
    let ts_limit        = 1.5e-5 in
    let skm_rate        = 2e-7 in
    let e_offset        = 6.0 *. ts_limit in (* 6 = offset_ratio *)
    let e_offset_qual   = 3.0 *. e_offset in
    let initial_p       = (1e-9, 0.0) in
    let shift_thres     = 0L in
    {skm_scale; ts_limit; skm_rate; e_offset; e_offset_qual; initial_p; shift_thres}

let delta_TSC newer older =
    let del = Int64.sub newer older in
    match (del >= 0L) with
    | true  -> del
    | false -> failwith "invalid ΔTSC!"

type nonce = {
    tsc:    counter;    (* the TSC value when we send it *)
    txts:   ts;         (* the random number that was in the transmit_timestamp of the packet we sent *)
}

type timestamps = {
    ta:     counter;
    tb:     float               [@printer fun fmt -> fprintf fmt "%.09f"];
    te:     float               [@printer fun fmt -> fprintf fmt "%.09f"];
{'fraction_non_alphanumeric': 0.09505472233481962, 'fraction_numerical': 0.020672882042967168, 'mean_word_length': 1.9872881355932204, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '467552', 'n_tokens_mistral': 1734, 'n_tokens_neox': 1619, 'n_words': 498}