using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DevelopEngine;
using System;
///
/// 学员操作记录类 用户收集各类 科目结束时上传回教员端
///
public class StudentOperateRecorder : Singleton
{
private NetAnswerSheet resultMsg;
DateTime startLearingTime;
///设置科目 并初始化存储类 每次设置科目时自动清空之前的记录
public void SetSubName(NetSubNameEnum netSubName)
{
resultMsg = new NetAnswerSheet();
resultMsg.subName = netSubName;
resultMsg.errors = new List();
resultMsg.deductMsg = new XDictionary();
}
///
/// 开始计时 每次训练场景加载完成开始计时 完成训练获取该数据时根据该数据计算用时
///
public void StartTiming()
{
startLearingTime = DateTime.Now;
}
///
/// 插入一条操作记录信息
///
/// 待记录的信息
/// 是否同时记录时间
public void InjectOperateMsg(string msg, bool addTime = false)
{
if (resultMsg.errors == null)
{
Debug.LogError("未设置科目进行初始化");
return;
}
if (addTime)//添加信息存入时的相对时间
{
msg = $"{GetTime()}:{msg}";
}
resultMsg.errors.Add(msg);
}
///
/// 记录一条本地化操作消息(存储为 key + 参数格式,显示时翻译)
///
public void InjectOperateMsgLocalized(string key, params object[] args)
{
if (resultMsg.errors == null)
{
Debug.LogError("未设置科目进行初始化");
return;
}
string stored = "\x01" + key;
if (args != null)
{
for (int i = 0; i < args.Length; i++)
stored += "\x02" + (args[i] == null ? "" : args[i].ToString());
}
resultMsg.errors.Add(stored);
}
///
/// 记录一条带时间前缀的本地化操作消息
///
public void InjectOperateMsgLocalizedWithTime(string key, params object[] args)
{
if (resultMsg.errors == null)
{
Debug.LogError("未设置科目进行初始化");
return;
}
string stored = "\x01{0}:\x02" + GetTime() + "\x02" + key;
if (args != null)
{
for (int i = 0; i < args.Length; i++)
stored += "\x02" + (args[i] == null ? "" : args[i].ToString());
}
resultMsg.errors.Add(stored);
}
///
/// 记录每个扣分项
///
/// 扣除分数
/// 扣分因素 后期需要调整权重的部分 不需要调整的可为空
public void InjectDecScore(float score, string factors)
{
if (score == 0) return;//不扣分的不计入
if (!string.IsNullOrEmpty(factors)) //需要记录扣分因素的
{
if (resultMsg.deductMsg.ContainsKey(factors))
{
resultMsg.deductMsg[factors] += score;//同因素扣分时 累加
}
else
{
resultMsg.deductMsg[factors] = score;//新的扣分因素 直接记录
}
}
resultMsg.score += score;//扣除的分数累加起来
}
///
/// 记录转运时间
///
public void InjectTransportTime(int time)
{
resultMsg.transportTime = time;
}
///
/// 获取上传消息
///
public NetAnswerSheet GetResultMsg()
{
resultMsg.totleTime = ((int)(DateTime.Now - startLearingTime).TotalSeconds).ToString();
return resultMsg;
}
//获取当前时间距离科目开始时刻的时长
private string GetTime()
{
TimeSpan ts = DateTime.Now - startLearingTime;
if (ts.Hours > 0)
return $"{ts.Hours}小时{ts.Minutes}分{ts.Seconds}秒";
else
return $"{ts.Minutes}分:{ts.Seconds}秒";
}
}