<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using Tera.Game.Messages;
using Data;
using DamageMeter.TeraDpsApi;
using Newtonsoft.Json;
using Tera.Game;
using DamageMeter.Skills.Skill;
using System.Net.Http;
using Newtonsoft.Json.Linq;
using System.IO;
using System.Globalization;

namespace DamageMeter
{
    public class DataExporter
    {

     
        public static void JsonExport(string json)
        {
            try
            {
                using (var client = new HttpClient())
                {
                    var response = client.PostAsync("http://cloud.neowutran.ovh:8083/store.php", new StringContent(
                    json,
                    Encoding.UTF8,
                    "application/json")
                    );
                    var responseString = response.Result.Content.ReadAsStringAsync();
                    Console.WriteLine(responseString.Result);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }

       
        public static void ToTeraDpsApi(SDespawnNpc despawnNpc, AbnormalityStorage abnormals)
        {
            if(!BasicTeraData.Instance.WindowData.Excel && 
                (string.IsNullOrEmpty(BasicTeraData.Instance.WindowData.TeraDpsToken) || string.IsNullOrEmpty(BasicTeraData.Instance.WindowData.TeraDpsUser)))
            {
                return;
            }

            if (!despawnNpc.Dead) return;
            
            var entity = DamageTracker.Instance.GetEntity(despawnNpc.Npc);

            if (!entity.IsBoss || !DamageTracker.Instance.EntitiesStats.ContainsKey(entity)) return;

            bool timedEncounter = false;

            //Nightmare desolarus
            if (entity.NpcE.Info.HuntingZoneId == 759 && entity.NpcE.Info.TemplateId == 1003)
            {
                timedEncounter = true;
            }

            var firstTick = DamageTracker.Instance.EntitiesStats[entity].FirstHit;
            var lastTick = DamageTracker.Instance.EntitiesStats[entity].LastHit;
            var interTick = lastTick - firstTick;
            var interval = interTick/TimeSpan.TicksPerSecond;
            if(interval == 0)
            {
                return;
            }
            var stats = DamageTracker.Instance.GetPlayerStats();
            var totaldamage = DamageTracker.Instance.TotalDamage(entity, timedEncounter);
            var partyDps = TimeSpan.TicksPerSecond * totaldamage / interTick;
         
            var teradpsData = new EncounterBase();
            teradpsData.areaId = entity.NpcE.Info.HuntingZoneId+"";
            teradpsData.bossId = entity.NpcE.Info.TemplateId+"";
            teradpsData.fightDuration = interval+"";
            teradpsData.partyDps = partyDps+"";
    
            foreach (var debuff in abnormals.Get(entity.NpcE))
            {
                long percentage = (debuff.Value.Duration(firstTick, lastTick) * 100 / interTick);
                if(percentage == 0)
                {
                    continue;
                }
                teradpsData.debuffUptime.Add(new KeyValuePair<string, string>(
                    debuff.Key.Id+"", percentage+""
                    ));
            }

            foreach (var user in stats)
            {
                var teradpsUser = new Members();
                var damage = user.Dealt.Damage(entity, timedEncounter);
                teradpsUser.playerTotalDamage = damage + "";

                if (damage <= 0)
                {
                    continue;
                }

                var buffs = abnormals.Get(user.Player);
                teradpsUser.playerClass = user.Class.ToString();
                teradpsUser.playerName = user.Name;
                teradpsUser.playerServer = BasicTeraData.Instance.Servers.GetServerName(user.Player.ServerId);
                teradpsUser.playerAverageCritRate = user.Dealt.CritRate(entity, timedEncounter) + "";
                teradpsUser.playerDps = TimeSpan.TicksPerSecond * damage / interTick + "";
                teradpsUser.playerTotalDamagePercentage = user.Dealt.DamageFraction(entity, totaldamage, timedEncounter) + "";

                var death = buffs.Death;
                teradpsUser.playerDeaths = death.Count(firstTick, lastTick) + "";
                teradpsUser.playerDeathDuration = death.Duration(firstTick, lastTick) / TimeSpan.TicksPerSecond + "";

                var aggro = buffs.Aggro(entity.NpcE);
                teradpsUser.aggro = aggro.Duration(firstTick, lastTick) / TimeSpan.TicksPerSecond + "";

                foreach (var buff in buffs.Times)
                {
                    long percentage = (buff.Value.Duration(firstTick, lastTick) * 100 / interTick);
                    if (percentage == 0)
                    {
                        continue;
                    }
                    teradpsUser.buffUptime.Add(new KeyValuePair<string, string>(
                        buff.Key.Id + "", percentage + ""
                    ));
                }
                var notimedskills = NoTimedSkills(timedEncounter ? user.Dealt.GetSkillsByTime(entity) : user.Dealt.GetSkills(entity));<commit_msg>Change aggro export seconds to %<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using Tera.Game.Messages;
using Data;
using DamageMeter.TeraDpsApi;
using Newtonsoft.Json;
using Tera.Game;
using DamageMeter.Skills.Skill;
using System.Net.Http;
using Newtonsoft.Json.Linq;
using System.IO;
using System.Globalization;

namespace DamageMeter
{
    public class DataExporter
    {

     
        public static void JsonExport(string json)
        {
            try
            {
                using (var client = new HttpClient())
                {
                    var response = client.PostAsync("http://cloud.neowutran.ovh:8083/store.php", new StringContent(
                    json,
                    Encoding.UTF8,
                    "application/json")
                    );
                    var responseString = response.Result.Content.ReadAsStringAsync();
                    Console.WriteLine(responseString.Result);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }

       
        public static void ToTeraDpsApi(SDespawnNpc despawnNpc, AbnormalityStorage abnormals)
        {
            if(!BasicTeraData.Instance.WindowData.Excel && 
                (string.IsNullOrEmpty(BasicTeraData.Instance.WindowData.TeraDpsToken) || string.IsNullOrEmpty(BasicTeraData.Instance.WindowData.TeraDpsUser)))
            {
                return;
            }

            if (!despawnNpc.Dead) return;
            
            var entity = DamageTracker.Instance.GetEntity(despawnNpc.Npc);

            if (!entity.IsBoss || !DamageTracker.Instance.EntitiesStats.ContainsKey(entity)) return;

            bool timedEncounter = false;

            //Nightmare desolarus
            if (entity.NpcE.Info.HuntingZoneId == 759 && entity.NpcE.Info.TemplateId == 1003)
            {
                timedEncounter = true;
            }

            var firstTick = DamageTracker.Instance.EntitiesStats[entity].FirstHit;
            var lastTick = DamageTracker.Instance.EntitiesStats[entity].LastHit;
            var interTick = lastTick - firstTick;
            var interval = interTick/TimeSpan.TicksPerSecond;
            if(interval == 0)
            {
                return;
            }
            var stats = DamageTracker.Instance.GetPlayerStats();
            var totaldamage = DamageTracker.Instance.TotalDamage(entity, timedEncounter);
            var partyDps = TimeSpan.TicksPerSecond * totaldamage / interTick;
         
            var teradpsData = new EncounterBase();
            teradpsData.areaId = entity.NpcE.Info.HuntingZoneId+"";
            teradpsData.bossId = entity.NpcE.Info.TemplateId+"";
            teradpsData.fightDuration = interval+"";
            teradpsData.partyDps = partyDps+"";
    
            foreach (var debuff in abnormals.Get(entity.NpcE))
            {
                long percentage = (debuff.Value.Duration(firstTick, lastTick) * 100 / interTick);
                if(percentage == 0)
                {
                    continue;
                }
                teradpsData.debuffUptime.Add(new KeyValuePair<string, string>(
                    debuff.Key.Id+"", percentage+""
                    ));
            }

            foreach (var user in stats)
            {
                var teradpsUser = new Members();
                var damage = user.Dealt.Damage(entity, timedEncounter);
                teradpsUser.playerTotalDamage = damage + "";

                if (damage <= 0)
                {
                    continue;
                }

                var buffs = abnormals.Get(user.Player);
                teradpsUser.playerClass = user.Class.ToString();
                teradpsUser.playerName = user.Name;
                teradpsUser.playerServer = BasicTeraData.Instance.Servers.GetServerName(user.Player.ServerId);
                teradpsUser.playerAverageCritRate = user.Dealt.CritRate(entity, timedEncounter) + "";
                teradpsUser.playerDps = TimeSpan.TicksPerSecond * damage / interTick + "";
                teradpsUser.playerTotalDamagePercentage = user.Dealt.DamageFraction(entity, totaldamage, timedEncounter) + "";

                var death = buffs.Death;
                teradpsUser.playerDeaths = death.Count(firstTick, lastTick) + "";
                teradpsUser.playerDeathDuration = death.Duration(firstTick, lastTick) / TimeSpan.TicksPerSecond + "";

                var aggro = buffs.Aggro(entity.NpcE);
                teradpsUser.aggro = 100* aggro.Duration(firstTick, lastTick) / interTick + "";

                foreach (var buff in buffs.Times)
                {
                    long percentage = (buff.Value.Duration(firstTick, lastTick) * 100 / interTick);
                    if (percentage == 0)
                    {
                        continue;
                    }
                    teradpsUser.buffUptime.Add(new KeyValuePair<string, string>(
                        buff.Key.Id + "", percentage + ""
                    ));
                }
                var notimedskills = NoTimedSkills(timedEncounter ? user.Dealt.GetSkillsByTime(entity) : user.Dealt.GetSkills(entity));
{'fraction_non_alphanumeric': 0.09200223713646533, 'fraction_numerical': 0.004381058911260253, 'mean_word_length': 1.668905472636816, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '3495153', 'n_tokens_mistral': 3001, 'n_tokens_neox': 2797, 'n_words': 481}