<commit_before>import { StudentsMap, StudentRecord } from "../store";
import {
  exec,
  query,
  write_text_file_to_project
} from "../../frame-editors/generic/client";
import { split } from "smc-util/misc2";

interface PathUseTimes {
  edit_times: number[];
  access_times: number[];
}

interface StudentUseTimes {
  student_id: string;
  account_id?: string;
  project_id?: string;
  student_name: string;
  assignment_path: string;
  paths?: { [path: string]: PathUseTimes };
  error?: string; // if it fails for some non-obvious reason
}

async function one_student_file_use_times(
  paths: string[],
  project_id: string,
  account_id: string,
  limit: number = 1000
): Promise<{ [path: string]: PathUseTimes }> {
  project_id = project_id;
  account_id = account_id;
  const times: { [path: string]: PathUseTimes } = {};
  for (const path of paths) {
    const q = await query({
      query: {
        file_use_times: {
          project_id,
          account_id,
          path,
          access_times: null,
          edit_times: null
        }
      },
      options: [{ limit }]
    });
    const { edit_times, access_times } = q.query.file_use_times;
    times[path] = { edit_times, access_times };
  }
  return times;
}

function student_info(
  assignment_path: string,
  student: StudentRecord,
  get_name: Function
): StudentUseTimes {
  const student_id = student.get("student_id");
  const x: StudentUseTimes = {
    student_id,
    student_name: get_name(student_id),
    assignment_path
  };
  for (const field of ["account_id", "project_id"]) {
    if (student.has(field)) {
      x[field] = student.get(field);
    }
  }
  return x;
}

async function paths_to_scan(
  project_id: string,
  src_path: string,
  target_path: string
): string[] {
  const { stdout } = await exec({
    command: "find",<commit_msg>fix type error that was blocking the Docker build<commit_after>import { StudentsMap, StudentRecord } from "../store";
import {
  exec,
  query,
  write_text_file_to_project
} from "../../frame-editors/generic/client";
import { split } from "smc-util/misc2";

interface PathUseTimes {
  edit_times: number[];
  access_times: number[];
}

interface StudentUseTimes {
  student_id: string;
  account_id?: string;
  project_id?: string;
  student_name: string;
  assignment_path: string;
  paths?: { [path: string]: PathUseTimes };
  error?: string; // if it fails for some non-obvious reason
}

async function one_student_file_use_times(
  paths: string[],
  project_id: string,
  account_id: string,
  limit: number = 1000
): Promise<{ [path: string]: PathUseTimes }> {
  project_id = project_id;
  account_id = account_id;
  const times: { [path: string]: PathUseTimes } = {};
  for (const path of paths) {
    const q = await query({
      query: {
        file_use_times: {
          project_id,
          account_id,
          path,
          access_times: null,
          edit_times: null
        }
      },
      options: [{ limit }]
    });
    const { edit_times, access_times } = q.query.file_use_times;
    times[path] = { edit_times, access_times };
  }
  return times;
}

function student_info(
  assignment_path: string,
  student: StudentRecord,
  get_name: Function
): StudentUseTimes {
  const student_id = student.get("student_id");
  const x: StudentUseTimes = {
    student_id,
    student_name: get_name(student_id),
    assignment_path
  };
  for (const field of ["account_id", "project_id"]) {
    if (student.has(field)) {
      x[field] = student.get(field);
    }
  }
  return x;
}

async function paths_to_scan(
  project_id: string,
  src_path: string,
  target_path: string
): Promise<string[]> {
  const { stdout } = await exec({
    command: "find",
{'fraction_non_alphanumeric': 0.12348341871124292, 'fraction_numerical': 0.0026961445133459154, 'mean_word_length': 3.2692750287687, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '3305652', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1223, 'n_words': 301}