public bool InsertProcessData(ProcessedData p)
        {
            using (var _dbcontext = new PayRollEntities())
            {
                var pd = (from d in _dbcontext.ProcessedData where d.Date == DbFunctions.TruncateTime(p.Date) && d.EmpCode == p.EmpCode select d).FirstOrDefault();

                if (pd != null)
                {
                    pd.HoursWorked             = p.HoursWorked;
                    pd.ShiftCount              = p.ShiftCount;
                    pd.Status                  = p.Status;
                    pd.ActualSalary            = p.ActualSalary;
                    pd.AduitingSalary          = p.AduitingSalary;
                    _dbcontext.Entry(pd).State = EntityState.Modified;
                    _dbcontext.SaveChanges();
                }
                else
                {
                    _dbcontext.ProcessedData.Add(p);
                    _dbcontext.SaveChanges();
                }

                return(true);
            }
        }
        private static ProcessedDataPackage CollectFor(Type type, ProcessedDataPackage cmd)
        {
            if (processors.ContainsKey(type) == false)
            {
                return(cmd);
            }

            DataProcessor dp = processors[type];

            ProcessedData t = null;

            if (dp.IsDataExists(cmd))
            {
                t = dp.ProcessData(cmd);
                if (t != null)
                {
                    if (cmd.ContainsKey(t.GetType()) == false)
                    {
                        cmd.Add(t.GetType(), t);
                    }
                }
            }

            return(cmd);
        }
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var fileValue     = value as IFormFile;
            var processedData = new ProcessedData();

            var  reader  = new StreamReader(fileValue.OpenReadStream());
            var  csv     = new CsvReader(reader);
            bool badData = false;

            csv.Configuration.BadDataFound = ctx =>
            {
                badData = true;
                processedData.BadRecords++;
            };
            csv.Configuration.RegisterClassMap <RepositoryMap>();
            csv.Configuration.RegisterClassMap <PullRequestMap>();
            csv.Configuration.RegisterClassMap <ReviewMap>();

            csv.Read();
            csv.ReadHeader();
            while (csv.Read())
            {
                processedData.TotalRecords++;
                if (!badData)
                {
                    var repository  = csv.GetRecord <Repository>();
                    var pullRequest = csv.GetRecord <PullRequest>();
                    var review      = csv.GetRecord <Review>();

                    if (!processedData.Repositories.Contains(repository))
                    {
                        processedData.Repositories.Add(repository);
                    }
                    else
                    {
                        repository = processedData.Repositories.Where(r => r.Id == repository.Id).Single();
                    }

                    var pullRequests = repository.PullRequests;
                    if (!pullRequests.Contains(pullRequest))
                    {
                        pullRequests.Add(pullRequest);
                    }
                    else
                    {
                        pullRequest = pullRequests.Where(p => p.Id == pullRequest.Id).Single();
                    }
                    pullRequest.Reviews.Add(review);
                }

                badData = false;
            }

            return(processedData);
        }
Example #4
0
 /// <summary>
 /// 将当前的内容序列化到查询中
 /// </summary>
 public override string SerializeAsQueryString()
 {
     if (PostedFile.Count > 0)
     {
         throw new InvalidOperationException("有文件附件时,不可以作为查询字符串,请使用POST查询。");
     }
     if (ProcessedData.Count == 0)
     {
         return(string.Empty);
     }
     return(ProcessedData.Select(s => s.Key + "=" + s.Value).Join("&"));
 }
Example #5
0
        protected override void Send(string reference, string action, IDictionary <string, string> data)
        {
            if (FailToSend)
            {
                var d = new ProcessedData
                {
                    Reference = reference,
                    Action    = action,
                    Data      = JsonConvert.SerializeObject(data)
                };
                _dataRepository.AddData(d);
                _dataRepository.Save();
                throw new SendErrorException();
            }



            //Dev-code
            switch (action)
            {
            case "BookingCompleted":
                SentToApisci["BookingComplete"] += 1;
                break;

            case "OutboundSegmentBooked":
                SentToApisci["OutboundSegmentBooked"] += 1;
                break;

            case "InboundSegmentBooked":
                SentToApisci["InboundSegmentBooked"] += 1;
                break;

            case "BookingModified":
                SentToApisci["BookingModified"] += 1;
                break;

            case "OutboundSegmentModified":
                SentToApisci["OutboundSegmentModified"] += 1;
                break;

            case "InboundSegmentModified":
                SentToApisci["InboundSegmentModified"] += 1;
                break;

            case "BookingCanceled":
                SentToApisci["BookingCanceled"] += 1;
                break;

            default:
                SentToApisci["ActionUnknown"] += 1;
                break;
            }
        }
        /// <summary>
        /// 计算长度
        /// </summary>
        /// <returns></returns>
        public override long ComputeLength()
        {
            if (ContentType == ContentType.FormData)
            {
                if (string.IsNullOrEmpty(RequestBoundary))
                {
                    RequestBoundary = "ifish_network_client_" + Guid.NewGuid().ToString().Replace("-", "");
                }

                var boundary = RequestBoundary;
                WebRequset.ContentType = "multipart/form-data; boundary=" + boundary;

                var size = ProcessedData.Where(s => s.Value != null).Select(
                    s =>
                    (long)2                                                                                                                         //--
                    + boundary.Length                                                                                                               //boundary
                    + 2                                                                                                                             //\r\n
                    + 43                                                                                                                            // content-disposition
                    + s.Key.Length                                                                                                                  //key
                    + Message.Encoding.GetByteCount(s.Value)                                                                                        //value
                    + 2                                                                                                                             //\r\n
                    ).Sum();

                //attach file
                size += PostedFile.Sum(s =>
                {
                    s.AttachContext(Context);
                    return(s.ComputeLength());
                });
                size += 4 + boundary.Length;                 //结束标记
                return(size);
            }
            else
            {
                if (ContentType == ContentType.FormUrlEncoded)
                {
                    return(SerializedDataString.Length);
                }
                else
                {
                    return(Math.Max(0, ProcessedData.Select(s => s.Key.Length + 1 + (s.Value == null ? 0 : (ContentType == ContentType.FormUrlEncoded ? s.Value.Length : Message.Encoding.GetByteCount(s.Value)))).Sum() + ProcessedData.Count - 1));
                }
            }
        }
Example #7
0
        public void Resend(ProcessedData processedData)
        {
            var reference = processedData.Reference;
            var action    = processedData.Action;
            var data      = JsonConvert.DeserializeObject <Dictionary <string, string> >(processedData.Data);

            try
            {
                Send(reference, action, data);
            }
            catch (SendErrorException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #8
0
    public void Parse(string _fileText)
    {
        ProcessedData.Clear();

        var lines    = _fileText.Split('\n');
        var rowCount = lines.Length;

        if (lines[lines.Length - 1] == "")
        {
            --rowCount;
        }

        for (int i = 0; i < rowCount; ++i)
        {
            ProcessedData.Add(new List <string>());
            var fields = lines[i].Split(',');
            for (int j = 0; j < fields.Length; ++j)
            {
                ProcessedData[i].Add(fields[j]);
            }
        }
    }
        /// <summary>
        /// HTTP POST to Apisci
        /// </summary>
        /// <param name="reference"></param>
        /// <param name="action"></param>
        /// <param name="data"></param>
        protected override void Send(string reference, string action, IDictionary <string, string> data)
        {
            //var serviceUrl = ConfigurationManager.AppSettings["Apisci.Service"];
            //var apiKey = ConfigurationManager.AppSettings["Apisci.ApiKey"];

            var serviceUrl = @"http://localhost:40170/api/Apisci";
            var apiKey     = "12345";

            var httpClient = new EasyHttp.Http.HttpClient
            {
                ThrowExceptionOnHttpError = false
            };


            var response = httpClient.Post(serviceUrl, new
            {
                Reference = reference,
                ApiKey    = apiKey,
                Action    = action,
                Data      = data
            }, "application/json");

            if (response.StatusCode != HttpStatusCode.OK)
            {
                //Saving processed data to database
                var processedData = new ProcessedData
                {
                    Reference = reference,
                    Action    = action,
                    Data      = JsonConvert.SerializeObject(data)
                };

                DataRepository.AddData(processedData);
                DataRepository.Save();

                throw new SendErrorException();
            }
        }
Example #10
0
 public void Calculate(IData data)
 {
     ProcessedData?.Invoke(GetCalculation(data));
 }
Example #11
0
 /// <summary>
 /// Write's compressed data.
 /// </summary>
 /// <param name="index">ReadData index.</param>
 /// <param name="data">Data to write.</param>
 public void WriteData(int index, byte[] data)
 {
     ProcessedData.TryAdd(index, data);
 }
Example #12
0
        public static string Match(string regExp, string inputString)
        {
            StringBuilder sb            = new StringBuilder();
            bool          ignoreOnMatch = regExp.ToLower().Contains("(?#ignore");

            try
            {
                //extract the function definitions from the expression
                ProcessedData pd = ExtractFunctions(regExp);


                Regex    re         = new Regex(pd.regExp);
                string[] groupNames = re.GetGroupNames();

                //process the expression
                MatchCollection collections = Regex.Matches(inputString, pd.regExp);

                //apply function expressions to matching groups

                //concatinate all the results
                foreach (Match match in collections)
                {
                    GroupCollection gc = match.Groups;

                    for (int x = 1; x < gc.Count; x++)
                    {
                        string groupName = groupNames[x];

                        //see if the group name refers to a defined function
                        RegExFunction functionRegEx = null;

                        if (pd.functionList != null)
                        {
                            foreach (RegExFunction fncInfo in pd.functionList)
                            {
                                if (Regex.IsMatch(groupName, fncInfo.name + @"\d+")) //we have a match, save the function
                                {
                                    functionRegEx = fncInfo;
                                    break;
                                }
                            }
                        }

                        if (functionRegEx != null) //we have a function, apply the function expression and use the result
                        {
                            if (functionRegEx.literalText)
                            {
                                sb.Append(functionRegEx.regExp);
                            }
                            else
                            {
                                sb.Append(Match(functionRegEx.regExp, gc[x].Value));
                            }
                        }
                        else //no function used
                        {
                            sb.Append(gc[x].Value);
                        }
                    }
                }
            }
            catch (System.Exception)
            {
                sb.Length = 0;
            }

            if (ignoreOnMatch && sb.Length != 0)
            {
                sb.Clear();
                sb.Append("Ignore");
            }

            return(sb.ToString());
        }
Example #13
0
        public void RunProcess()
        {
            //If any files are in queue to be sent
            var savedData  = _serviceFacade.GetUnSentData();
            var hasChanged = false;

            if (savedData.Any())
            {
                Logger.Info("Unsent data found.");

                //Send
                ProcessedData item = new ProcessedData();
                try
                {
                    while (savedData.Count > 0)
                    {
                        item = savedData.Dequeue();
                        Policy
                        .Handle <SendErrorException>()
                        .WaitAndRetry(2, retryCount => TimeSpan.FromSeconds(1))
                        .Execute(() =>
                                 Posting.SendTest(item.Reference, item.Action,
                                                  JsonConvert.DeserializeObject <Dictionary <string, string> >(item.Data)));
                        _serviceFacade.RemoveData(item);
                        hasChanged = true;
                        Logger.Info("Successfully sent all data");
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error("Could not send files");
                    //Save processed but not sent data to database
                    while (savedData.Count > 0)
                    {
                        _serviceFacade.AddProcessedData(item);
                        item = savedData.Dequeue();
                    }
                    _serviceFacade.Save();
                }

                finally
                {
                    if (hasChanged)
                    {
                        _serviceFacade.Save();
                    }
                }
            }

            //No saved data exists
            if (!savedData.Any())
            {
                Logger.Info("LastProcessedFile: " + _serviceFacade.GetLastProcessedDate());
                var listOfFileSets = _serviceFacade.GetNewSetsOfFiles(_fileList).ToList();
                hasChanged = false;
                var listOfFileSetsBackup = listOfFileSets;
                var processedQueue       = new Queue <ProcessedData>();

                //Process
                if (listOfFileSets.Any())
                {
                    foreach (var fileSet in listOfFileSets.OrderBy(f => f.Key))
                    {
                        var lastProcessedFileSet = DateTime.ParseExact(_serviceFacade.GetLastProcessedDate(), "yyyyMMdd",
                                                                       CultureInfo.InvariantCulture);

                        if (fileSet.Key == lastProcessedFileSet.AddDays(1))
                        {
                            Logger.Info("Will process new sets of files");
                            //Prepare files before sending
                            processedQueue = _serviceFacade.ProcessFile(fileSet);
                            _serviceFacade.AddOrUpdateLastProcessedDate(fileSet.Key.ToString("yyyyMMdd"));
                            hasChanged = true;
                        }
                    }

                    //Send
                    ProcessedData item = new ProcessedData();
                    try
                    {
                        while (processedQueue.Count > 0)
                        {
                            item = processedQueue.Dequeue();
                            Policy
                            .Handle <SendErrorException>()
                            .WaitAndRetry(2, retryCount => TimeSpan.FromSeconds(1))
                            .Execute(() =>
                                     Posting.SendTest(item.Reference, item.Action,
                                                      JsonConvert.DeserializeObject <Dictionary <string, string> >(item.Data))
                                     );

                            Logger.Info("Successfully sent all data");
                        }
                    }

                    catch (Exception ex)
                    {
                        Logger.Error("Could not send files");
                        //Save processed but not sent data to database
                        while (processedQueue.Count > 0)
                        {
                            _serviceFacade.AddProcessedData(item);
                            item = processedQueue.Dequeue();
                        }
                        _serviceFacade.Save();
                    }

                    finally
                    {
                        if (hasChanged)
                        {
                            _serviceFacade.Save();
                        }
                    }
                }
            }
        }
Example #14
0
        //Program entry point
        static void Main(string[] args)
        {
            string cfgPath = "config.cfg";

            bool   recursive           = false;
            bool   steaminfo           = false;
            bool   clear               = false;
            bool   parseChickens       = true;
            string outputRootFolder    = "parsed";
            bool   sameFilename        = false;
            bool   sameFolderStructure = false;
            bool   lowOutputMode       = false;

            List <string> foldersToProcess = new List <string>();
            List <string> demosToProcess   = new List <string>();

            if (args.Count() == 0)
            {
                helpText();
                return;
            }

            for (int i = 0; i < args.Count(); i++)
            {
                var arg = args[i].ToLower();

                if (arg == "-config")
                {
                    if (i < args.Count())
                    {
                        cfgPath = args[i + 1];
                    }

                    i++;
                }
                else if (arg == "-folders")
                {
                    bool searching = true;
                    while (i < args.Count() - 1 && searching)
                    {
                        i++;

                        if (args[i][0] == '-')
                        {
                            searching = false;
                        }
                        else
                        {
                            foldersToProcess.Add(args[i]);
                        }
                    }
                    i--;
                }
                else if (arg == "-demos")
                {
                    bool searching = true;
                    while (i < args.Count() - 1 && searching)
                    {
                        i++;

                        if (args[i][0] == '-')
                        {
                            searching = false;
                        }
                        else
                        {
                            demosToProcess.Add(args[i]);
                        }
                    }
                    i--;
                }
                else if (arg == "-output")
                {
                    outputRootFolder = args[i + 1];
                    i++;
                }
                else if (arg == "-clear")
                {
                    clear = true;
                }
                else if (arg == "-steaminfo")
                {
                    steaminfo = true;
                }
                else if (arg == "-recursive")
                {
                    recursive = true;
                }
                else if (arg == "-help")
                {
                    helpText();
                    return;
                }
                else if (arg == "-nochickens")
                {
                    parseChickens = false;
                }
                else if (arg == "-samefilename")
                {
                    sameFilename = true;
                }
                else if (arg == "-samefolderstructure")
                {
                    sameFolderStructure = true;
                }
                else if (arg == "-lowoutputmode")
                {
                    lowOutputMode = true;
                }
            }

            if (steaminfo)
            {
                if (File.Exists(cfgPath))
                {
                    try
                    {
                        Config cfg = new Config(cfgPath);

                        Steam.setAPIKey(cfg.keyVals["apikey"]);

                        if (Steam.getSteamUserNamesLookupTable(new List <long>()
                        {
                            76561198072130043
                        }) == null)
                        {
                            throw new Exception("CONFIG::STEAM_API_KEY::INVALID");
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.Error("CONFIG ERROR... INFO:: {0}\nSteam names will not be retrieved!!!", e.Message);
                        steaminfo = false;
                    }
                }
                else
                {
                    Debug.Error("Config unreadable... Steam names will not be retrieved!!!");
                    steaminfo = false;
                }
            }

            //Clear by recreating folder
            if (clear && Directory.Exists(outputRootFolder))
            {
                Directory.Delete(outputRootFolder, true);
                Directory.CreateDirectory(outputRootFolder);
            }
            else if (!Directory.Exists(outputRootFolder))
            {
                Directory.CreateDirectory(outputRootFolder);
            }

            List <DemoInformation> demosInformation = new List <DemoInformation>();

            foreach (string folder in foldersToProcess)
            {
                try
                {
                    string[] subDemos = Directory.GetFiles(Path.GetFullPath(folder), "*.dem", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
                    foreach (string demo in subDemos)
                    {
                        string[] pathSplit = demo.Split('\\');
                        string   testDate, testType, mapname;

                        Guid     guid;
                        string[] filenameSplit = pathSplit[pathSplit.Count() - 1].Split('.');
                        bool     isFaceitDemo  = Guid.TryParse(filenameSplit[0], out guid);

                        if (isFaceitDemo)
                        {
                            testDate = "unknown";
                            testType = "unknown";
                            mapname  = "unknown";
                        }
                        else
                        {
                            filenameSplit = pathSplit[pathSplit.Count() - 1].Split('_', '.');

                            bool isSEDiscordDemo = filenameSplit.Count() > 5 ? true : false;

                            if (isSEDiscordDemo)
                            {
                                testDate = $"{ filenameSplit[1] }/{ filenameSplit[0] }/{ filenameSplit[2] }";
                                testType = $"{ filenameSplit[filenameSplit.Count() - 2] }";
                                mapname  = $"{ filenameSplit[3] }";

                                for (int i = 4; i < filenameSplit.Count() - 2; i++)
                                {
                                    mapname += $"_{ filenameSplit[i] }";
                                }
                            }
                            else //cannot determine demo name format
                            {
                                testDate = "unknown";
                                testType = "unknown";
                                mapname  = "unknown";
                            }
                        }

                        demosInformation.Add(new DemoInformation()
                        {
                            DemoName = demo, MapName = mapname, TestDate = testDate, TestType = testType
                        });
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
            }

            foreach (string demo in demosToProcess)
            {
                try
                {
                    string testDate, testType, mapname;

                    Guid     guid;
                    string[] filenameSplit = demo.Split('.');
                    bool     isFaceitDemo  = Guid.TryParse(filenameSplit[0], out guid);

                    if (isFaceitDemo)
                    {
                        testDate = "unknown";
                        testType = "unknown";
                        mapname  = "unknown";
                    }
                    else
                    {
                        filenameSplit = demo.Split('_', '.');

                        bool isSEDiscordDemo = filenameSplit.Count() > 5 ? true : false;

                        if (isSEDiscordDemo)
                        {
                            testDate = $"{ filenameSplit[1] }/{ filenameSplit[0] }/{ filenameSplit[2] }";
                            testType = $"{ filenameSplit[filenameSplit.Count() - 2] }";
                            mapname  = $"{ filenameSplit[3] }";

                            for (int i = 4; i < filenameSplit.Count() - 2; i++)
                            {
                                mapname += $"_{ filenameSplit[i] }";
                            }
                        }
                        else //cannot determine demo name format
                        {
                            testDate = "unknown";
                            testType = "unknown";
                            mapname  = "unknown";
                        }
                    }

                    demosInformation.Add(new DemoInformation()
                    {
                        DemoName = demo, MapName = mapname, TestDate = testDate, TestType = testType
                    });
                }
                catch (Exception e)
                {
                    throw e;
                }
            }

            Debug.Info("Starting processing of {0} demos.\n", demosInformation.Count());
            DateTime startTime = DateTime.Now;

            int passCount = 0;

            Console.CursorVisible = false;
            //Process all the found demos
            for (int i = 0; i < demosInformation.Count(); i++)
            {
                Console.WriteLine($"Parsing demo {demosInformation[i].DemoName}");

                MatchData mdTest = MatchData.FromDemoFile(demosInformation[i].DemoName, parseChickens, lowOutputMode);

                IEnumerable <MatchStartedEventArgs>        mse = new List <MatchStartedEventArgs>();
                IEnumerable <SwitchSidesEventArgs>         sse = new List <SwitchSidesEventArgs>();
                IEnumerable <FeedbackMessage>              fme = new List <FeedbackMessage>();
                IEnumerable <TeamPlayers>                  tpe = new List <TeamPlayers>();
                IEnumerable <PlayerKilledEventArgs>        pke = new List <PlayerKilledEventArgs>();
                Dictionary <string, IEnumerable <Player> > pe  = new Dictionary <string, IEnumerable <Player> >();
                IEnumerable <Equipment>          pwe           = new List <Equipment>();
                IEnumerable <int>                poe           = new List <int>();
                IEnumerable <BombPlanted>        bpe           = new List <BombPlanted>();
                IEnumerable <BombExploded>       bee           = new List <BombExploded>();
                IEnumerable <BombDefused>        bde           = new List <BombDefused>();
                IEnumerable <HostageRescued>     hre           = new List <HostageRescued>();
                IEnumerable <HostagePickedUp>    hpu           = new List <HostagePickedUp>();
                IEnumerable <DisconnectedPlayer> dpe           = new List <DisconnectedPlayer>();
                IEnumerable <Team>               te            = new List <Team>();
                IEnumerable <RoundEndReason>     re            = new List <RoundEndReason>();
                IEnumerable <double>             le            = new List <double>();
                IEnumerable <TeamEquipmentStats> tes           = new List <TeamEquipmentStats>();
                IEnumerable <NadeEventArgs>      ge            = new List <NadeEventArgs>();
                //IEnumerable<SmokeEventArgs> gse = new List<SmokeEventArgs>();
                //IEnumerable<FlashEventArgs> gfe = new List<FlashEventArgs>();
                //IEnumerable<GrenadeEventArgs> gge = new List<GrenadeEventArgs>();
                //IEnumerable<FireEventArgs> gie = new List<FireEventArgs>();
                //IEnumerable<DecoyEventArgs> gde = new List<DecoyEventArgs>();
                IEnumerable <ChickenKilledEventArgs> cke = new List <ChickenKilledEventArgs>();
                IEnumerable <ShotFired> sfe = new List <ShotFired>();

                mse = (from start in mdTest.GetEvents <MatchStartedEventArgs>()
                       select(start as MatchStartedEventArgs));

                sse = (from switchSide in mdTest.GetEvents <SwitchSidesEventArgs>()
                       select(switchSide as SwitchSidesEventArgs));

                fme = (from message in mdTest.GetEvents <FeedbackMessage>()
                       select(message as FeedbackMessage));

                pke = (from player in mdTest.GetEvents <PlayerKilledEventArgs>()
                       select(player as PlayerKilledEventArgs));

                pe.Add("Kills", from player in mdTest.GetEvents <PlayerKilledEventArgs>()
                       select(player as PlayerKilledEventArgs).Killer);

                pe.Add("Deaths", from player in mdTest.GetEvents <PlayerKilledEventArgs>()
                       select(player as PlayerKilledEventArgs).Victim);

                pe.Add("Headshots", from player in mdTest.GetEvents <PlayerKilledEventArgs>()
                       where (player as PlayerKilledEventArgs).Headshot
                       select(player as PlayerKilledEventArgs).Killer);

                pe.Add("Assists", from player in mdTest.GetEvents <PlayerKilledEventArgs>()
                       where (player as PlayerKilledEventArgs).Assister != null
                       select(player as PlayerKilledEventArgs).Assister);

                pwe = (from weapon in mdTest.GetEvents <PlayerKilledEventArgs>()
                       select(weapon as PlayerKilledEventArgs).Weapon);

                poe = (from penetration in mdTest.GetEvents <PlayerKilledEventArgs>()
                       select(penetration as PlayerKilledEventArgs).PenetratedObjects);

                pe.Add("MVPs", from player in mdTest.GetEvents <RoundMVPEventArgs>()
                       select(player as RoundMVPEventArgs).Player);

                pe.Add("Shots", from player in mdTest.GetEvents <WeaponFiredEventArgs>()
                       select(player as WeaponFiredEventArgs).Shooter);

                pe.Add("Plants", from player in mdTest.GetEvents <BombPlanted>()
                       select(player as BombPlanted).Player);

                pe.Add("Defuses", from player in mdTest.GetEvents <BombDefused>()
                       select(player as BombDefused).Player);

                pe.Add("Rescues", from player in mdTest.GetEvents <HostageRescued>()
                       select(player as HostageRescued).Player);

                bpe = (from plant in mdTest.GetEvents <BombPlanted>()
                       select plant as BombPlanted)
                      .GroupBy(p => p.Round)
                      .Select(p => p.FirstOrDefault());

                bee = (from explode in mdTest.GetEvents <BombExploded>()
                       select explode as BombExploded)
                      .GroupBy(p => p.Round)
                      .Select(p => p.FirstOrDefault());

                bde = (from defuse in mdTest.GetEvents <BombDefused>()
                       select defuse as BombDefused)
                      .GroupBy(p => p.Round)
                      .Select(p => p.FirstOrDefault());

                hre = (from hostage in mdTest.GetEvents <HostageRescued>()
                       select hostage as HostageRescued);

                hpu = (from hostage in mdTest.GetEvents <HostagePickedUp>()
                       select hostage as HostagePickedUp);

                dpe = (from disconnection in mdTest.GetEvents <DisconnectedPlayer>()
                       select(disconnection as DisconnectedPlayer));

                te = (from team in mdTest.GetEvents <RoundEndedEventArgs>()
                      select(team as RoundEndedEventArgs).Winner);

                re = (from reason in mdTest.GetEvents <RoundEndedEventArgs>()
                      select(reason as RoundEndedEventArgs).Reason);

                le = (from length in mdTest.GetEvents <RoundEndedEventArgs>()
                      select(length as RoundEndedEventArgs).Length);

                tpe = (from teamPlayers in mdTest.GetEvents <TeamPlayers>()
                       where (teamPlayers as TeamPlayers).Round <= te.Count() // removes extra TeamPlayers if freezetime_end event triggers once a playtest is finished
                       select(teamPlayers as TeamPlayers));

                tes = (from round in mdTest.GetEvents <TeamEquipmentStats>()
                       select(round as TeamEquipmentStats));

                ge = (from nade in mdTest.GetEvents <NadeEventArgs>()
                      select(nade as NadeEventArgs));

                cke = (from chickenKill in mdTest.GetEvents <ChickenKilledEventArgs>()
                       select(chickenKill as ChickenKilledEventArgs));

                sfe = (from shot in mdTest.GetEvents <ShotFired>()
                       select(shot as ShotFired));

                tanookiStats tanookiStats = tanookiStatsCreator(tpe, dpe);


                if (mdTest.passed)
                {
                    // create the json output files using the data gathered
                    var processedData = new ProcessedData()
                    {
                        DemoInformation          = demosInformation[i],
                        SameFilename             = sameFilename,
                        SameFolderStructure      = sameFolderStructure,
                        ParseChickens            = parseChickens,
                        FoldersToProcess         = foldersToProcess,
                        OutputRootFolder         = outputRootFolder,
                        tanookiStats             = tanookiStats,
                        MatchStartValues         = mse,
                        SwitchSidesValues        = sse,
                        MessagesValues           = fme,
                        TeamPlayersValues        = tpe,
                        PlayerKilledEventsValues = pke,
                        PlayerValues             = pe,
                        WeaponValues             = pwe,
                        PenetrationValues        = poe,
                        BombsitePlantValues      = bpe,
                        BombsiteExplodeValues    = bee,
                        BombsiteDefuseValues     = bde,
                        HostageRescueValues      = hre,
                        HostagePickedUpValues    = hpu,
                        TeamValues           = te,
                        RoundEndReasonValues = re,
                        RoundLengthValues    = le,
                        TeamEquipmentValues  = tes,
                        GrenadeValues        = ge,
                        ChickenValues        = cke,
                        ShotsFiredValues     = sfe,
                        WriteTicks           = true
                    };

                    var allStats = mdTest.CreateFiles(processedData);

                    passCount++;

                    Console.WriteLine($"Finished parsing demo {demosInformation[i].DemoName}.\n");
                }
                else
                {
                    Console.WriteLine($"Failed parsing demo {demosInformation[i].DemoName}.\n");
                }
            }

            Console.CursorVisible = true;

            Debug.Blue("========== PROCESSING COMPLETE =========\n");
            DateTime end = DateTime.Now;

            Debug.White("Processing took {0} minutes\n", (end - startTime).TotalMinutes);
            Debug.White("Passed: {0}\n", passCount);
            Debug.White("Failed: {0}\n", demosInformation.Count() - passCount);
        }
Example #15
0
 void Awake()
 {
     instance = this;
 }
Example #16
0
        public void MockData()
        {
            var DemoInformation = new DemoInformation()
            {
                DemoName = "demo1",
                MapName  = "de_testmap",
                TestDate = new DateTime(2020, 1, 1, 0, 0, 0).ToString(),
                TestType = "Defuse",
            };

            var tanookiStats = new tanookiStats()
            {
                Joined       = true,
                Left         = true,
                RoundJoined  = 1,
                RoundLeft    = 2,
                RoundsLasted = 1,
            };

            var MatchStartValues = new List <MatchStartedEventArgs>()
            {
                new MatchStartedEventArgs
                {
                    Mapname      = "de_testmap",
                    HasBombsites = true,
                }
            };

            var SwitchSidesValues = new List <SwitchSidesEventArgs>()
            {
                new SwitchSidesEventArgs
                {
                    RoundBeforeSwitch = 1,
                }
            };

            var MessagesValues = new List <FeedbackMessage>()
            {
                new FeedbackMessage()
                {
                    Round                        = 1,
                    SteamID                      = 12321313213,
                    TeamName                     = "AlphaTeam",
                    XCurrentPosition             = 50,
                    YCurrentPosition             = 60,
                    ZCurrentPosition             = 70,
                    XLastAlivePosition           = 120,
                    YLastAlivePosition           = 130,
                    ZLastAlivePosition           = 140,
                    XCurrentViewAngle            = 45.0f,
                    YCurrentViewAngle            = 225.0f,
                    SetPosCommandCurrentPosition = "setpos 50 60 70; setang 45 225",
                    Message                      = "bad map",
                    TimeInRound                  = 31.7568,
                }
            };

            var TeamPlayersValues = new List <TeamPlayers>()
            {
                new TeamPlayers()
                {
                    Round      = 1,
                    Terrorists = new List <Player>()
                    {
                        new Player
                        {
                            Name              = "JimWood",
                            SteamID           = 32443298432,
                            EntityID          = 45,
                            UserID            = 1,
                            LastAlivePosition = new Vector()
                            {
                                X = 100,
                                Y = 100,
                                Z = 100,
                            },
                            Position = new Vector()
                            {
                                X = 200,
                                Y = 200,
                                Z = 200,
                            },
                            Money = 200,
                            RoundStartEquipmentValue = 2700,
                        }
                    },
                    CounterTerrorists = new List <Player>()
                    {
                        new Player
                        {
                            Name              = "TheWhaleMan",
                            SteamID           = 12321313213,
                            EntityID          = 46,
                            UserID            = 2,
                            LastAlivePosition = new Vector()
                            {
                                X = 90,
                                Y = 900,
                                Z = 9000,
                            },
                            Position = new Vector()
                            {
                                X = 80,
                                Y = 800,
                                Z = 8000,
                            },
                            Money = 200,
                            RoundStartEquipmentValue = 200,
                        }
                    }
                },
                new TeamPlayers()
                {
                    Round      = 2,
                    Terrorists = new List <Player>()
                    {
                        new Player
                        {
                            Name              = "TheWhaleMan",
                            SteamID           = 12321313213,
                            EntityID          = 46,
                            UserID            = 2,
                            LastAlivePosition = new Vector()
                            {
                                X = 400,
                                Y = 400,
                                Z = 400,
                            },
                            Position = new Vector()
                            {
                                X = 500,
                                Y = 500,
                                Z = 500,
                            },
                            Money = 1000,
                            RoundStartEquipmentValue = 200,
                        }
                    },
                    CounterTerrorists = new List <Player>()
                    {
                        new Player
                        {
                            Name              = "JimWood",
                            SteamID           = 32443298432,
                            EntityID          = 45,
                            UserID            = 1,
                            LastAlivePosition = new Vector()
                            {
                                X = 70,
                                Y = 70,
                                Z = 70,
                            },
                            Position = new Vector()
                            {
                                X = 60,
                                Y = 60,
                                Z = 60,
                            },
                            Money = 5000,
                            RoundStartEquipmentValue = 4750,
                        }
                    }
                }
            };

            var PlayerKilledEventsValues = new List <PlayerKilledEventArgs>()
            {
                new PlayerKilledEventArgs
                {
                    Round               = 1,
                    TimeInRound         = 40,
                    Killer              = TeamPlayersValues[0].Terrorists[0],
                    Victim              = TeamPlayersValues[0].CounterTerrorists[0],
                    Assister            = null,
                    KillerBotTakeover   = false,
                    VictimBotTakeover   = false,
                    AssisterBotTakeover = false,
                    Headshot            = true,
                    Suicide             = false,
                    TeamKill            = false,
                    PenetratedObjects   = 0,
                    AssistedFlash       = false,
                },
                new PlayerKilledEventArgs
                {
                    Round               = 2,
                    TimeInRound         = 90,
                    Killer              = TeamPlayersValues[1].CounterTerrorists[0],
                    Victim              = TeamPlayersValues[1].Terrorists[0],
                    Assister            = null,
                    KillerBotTakeover   = true,
                    VictimBotTakeover   = true,
                    AssisterBotTakeover = true,
                    Headshot            = true,
                    Suicide             = false,
                    TeamKill            = false,
                    PenetratedObjects   = 1,
                    AssistedFlash       = true,
                }
            };

            var PlayerValues = new Dictionary <string, IEnumerable <Player> >()
            {
                {
                    "Kills",
                    new List <Player>()
                    {
                        TeamPlayersValues[0].Terrorists[0],
                        TeamPlayersValues[1].CounterTerrorists[0],
                    }
                },
                {
                    "Deaths",
                    new List <Player>()
                    {
                        TeamPlayersValues[0].CounterTerrorists[0],
                        TeamPlayersValues[1].Terrorists[0],
                    }
                },
                {
                    "Headshots",
                    new List <Player>()
                    {
                        TeamPlayersValues[0].Terrorists[0],
                    }
                },
                {
                    "Assists",
                    new List <Player>()
                    {
                        TeamPlayersValues[0].CounterTerrorists[0],
                    }
                },
                {
                    "MVPs",
                    new List <Player>()
                    {
                        TeamPlayersValues[0].Terrorists[0],
                        TeamPlayersValues[1].CounterTerrorists[0],
                    }
                },
                {
                    "Shots",
                    new List <Player>()
                    {
                        TeamPlayersValues[0].Terrorists[0],
                        TeamPlayersValues[0].Terrorists[0],
                        TeamPlayersValues[0].Terrorists[0],
                        TeamPlayersValues[1].Terrorists[0],
                        TeamPlayersValues[1].CounterTerrorists[0],
                        TeamPlayersValues[1].CounterTerrorists[0],
                        TeamPlayersValues[1].CounterTerrorists[0],
                    }
                },
                {
                    "Plants",
                    new List <Player>()
                    {
                        TeamPlayersValues[0].Terrorists[0],
                        TeamPlayersValues[1].Terrorists[0],
                    }
                },
                {
                    "Defuses",
                    new List <Player>()
                    {
                        TeamPlayersValues[1].CounterTerrorists[0],
                    }
                },
                {
                    "Rescues",
                    new List <Player>()
                    {
                        TeamPlayersValues[0].CounterTerrorists[0],
                        TeamPlayersValues[0].CounterTerrorists[0],
                    }
                }
            };

            var WeaponValues = new List <Equipment>()
            {
                new Equipment
                {
                    Owner  = TeamPlayersValues[0].Terrorists[0],
                    Weapon = EquipmentElement.AK47
                },
                new Equipment
                {
                    Owner  = TeamPlayersValues[0].CounterTerrorists[0],
                    Weapon = EquipmentElement.AWP
                }
            };

            var PenetrationValues = new List <int>()
            {
                0,
                1,
            };

            var BombsitePlantValues = new List <BombPlanted>()
            {
                new BombPlanted
                {
                    Bombsite    = 'A',
                    Player      = TeamPlayersValues[0].Terrorists[0],
                    Round       = 1,
                    TimeInRound = 35,
                    XPosition   = 100,
                    YPosition   = 100,
                    ZPosition   = 100,
                },
                new BombPlanted
                {
                    Bombsite    = 'B',
                    Player      = TeamPlayersValues[1].Terrorists[0],
                    Round       = 2,
                    TimeInRound = 60,
                    XPosition   = 400,
                    YPosition   = 400,
                    ZPosition   = 400,
                }
            };

            var BombsiteExplodeValues = new List <BombExploded>()
            {
                new BombExploded
                {
                    Bombsite    = 'A',
                    Player      = TeamPlayersValues[0].Terrorists[0],
                    Round       = 1,
                    TimeInRound = 75,
                }
            };

            var BombsiteDefuseValues = new List <BombDefused>()
            {
                new BombDefused
                {
                    Bombsite    = 'B',
                    Player      = TeamPlayersValues[1].CounterTerrorists[0],
                    Round       = 2,
                    TimeInRound = 100,
                    HasKit      = true,
                }
            };

            var HostageRescueValues = new List <HostageRescued>()
            {
                new HostageRescued
                {
                    Hostage      = 'A',
                    HostageIndex = 250,
                    RescueZone   = 0,
                    Player       = TeamPlayersValues[0].CounterTerrorists[0],
                    Round        = 1,
                    TimeInRound  = 50,
                    XPosition    = 800,
                    YPosition    = 800,
                    ZPosition    = 800,
                },
                new HostageRescued
                {
                    Hostage      = 'B',
                    HostageIndex = 251,
                    RescueZone   = 0,
                    Player       = TeamPlayersValues[0].CounterTerrorists[0],
                    Round        = 1,
                    TimeInRound  = 51,
                    XPosition    = 700,
                    YPosition    = 700,
                    ZPosition    = 700,
                }
            };

            var HostagePickedUpValues = new List <HostagePickedUp>()
            {
                new HostagePickedUp
                {
                    Hostage      = 'A',
                    HostageIndex = 250,
                    Player       = TeamPlayersValues[0].CounterTerrorists[0],
                    Round        = 1,
                    TimeInRound  = 20,
                },
                new HostagePickedUp
                {
                    Hostage      = 'B',
                    HostageIndex = 251,
                    Player       = TeamPlayersValues[0].CounterTerrorists[0],
                    Round        = 1,
                    TimeInRound  = 35,
                },
                new HostagePickedUp
                {
                    Hostage      = 'A',
                    HostageIndex = 250,
                    Player       = TeamPlayersValues[1].CounterTerrorists[0],
                    Round        = 2,
                    TimeInRound  = 40,
                }
            };

            var TeamValues = new List <Team>()
            {
                Team.Terrorist,
                Team.CounterTerrorist,
            };

            var RoundEndReasonValues = new List <RoundEndReason>()
            {
                RoundEndReason.TargetBombed,
                RoundEndReason.BombDefused,
            };

            var RoundLengthValues = new List <double>()
            {
                80,
                105,
            };

            var TeamEquipmentValues = new List <TeamEquipmentStats>()
            {
                new TeamEquipmentStats
                {
                    Round         = 1,
                    TEquipValue   = 2900,
                    TExpenditure  = 200,
                    CTEquipValue  = 450,
                    CTExpenditure = 50,
                },
                new TeamEquipmentStats
                {
                    Round         = 2,
                    TEquipValue   = 800,
                    TExpenditure  = 600,
                    CTEquipValue  = 5750,
                    CTExpenditure = 1000,
                }
            };

            var GrenadeValues = new List <NadeEventArgs>()
            {
                new FlashEventArgs
                {
                    NadeType = EquipmentElement.Flash,
                    ThrownBy = TeamPlayersValues[0].Terrorists[0],
                    Position = new Vector()
                    {
                        X = 500,
                        Y = 500,
                        Z = 500,
                    },
                    FlashedPlayers = new Player[1]
                    {
                        TeamPlayersValues[0].CounterTerrorists[0]
                    }
                } as NadeEventArgs,
                new NadeEventArgs
                {
                    NadeType = EquipmentElement.Smoke,
                    ThrownBy = TeamPlayersValues[0].Terrorists[0],
                    Position = new Vector()
                    {
                        X = 500,
                        Y = 500,
                        Z = 500,
                    },
                },
                new NadeEventArgs
                {
                    NadeType = EquipmentElement.HE,
                    ThrownBy = TeamPlayersValues[0].Terrorists[0],
                    Position = new Vector()
                    {
                        X = 500,
                        Y = 500,
                        Z = 500,
                    },
                },
                new NadeEventArgs
                {
                    NadeType = EquipmentElement.Molotov,                     // all molotovs are down as incendiaries, specified why in DemoParser.cs, search for "FireNadeStarted".
                    ThrownBy = TeamPlayersValues[0].Terrorists[0],
                    Position = new Vector()
                    {
                        X = 500,
                        Y = 500,
                        Z = 500,
                    },
                },
                new NadeEventArgs
                {
                    NadeType = EquipmentElement.Incendiary,
                    ThrownBy = TeamPlayersValues[0].Terrorists[0],
                    Position = new Vector()
                    {
                        X = 500,
                        Y = 500,
                        Z = 500,
                    },
                },
                new NadeEventArgs
                {
                    NadeType = EquipmentElement.Decoy,
                    ThrownBy = TeamPlayersValues[0].Terrorists[0],
                    Position = new Vector()
                    {
                        X = 500,
                        Y = 500,
                        Z = 500,
                    },
                }
            };

            var ChickenValues = new List <ChickenKilledEventArgs>()
            {
                new ChickenKilledEventArgs {
                }
            };

            var ShotsFiredValues = new List <ShotFired>()
            {
                new ShotFired
                {
                    Round   = 1,
                    Shooter = TeamPlayersValues[0].Terrorists[0]
                },
                new ShotFired
                {
                    Round   = 1,
                    Shooter = TeamPlayersValues[0].Terrorists[0]
                },
                new ShotFired
                {
                    Round   = 1,
                    Shooter = TeamPlayersValues[0].Terrorists[0]
                },
                new ShotFired
                {
                    Round   = 2,
                    Shooter = TeamPlayersValues[1].Terrorists[0]
                },
                new ShotFired
                {
                    Round   = 2,
                    Shooter = TeamPlayersValues[1].CounterTerrorists[0]
                },
                new ShotFired
                {
                    Round   = 2,
                    Shooter = TeamPlayersValues[1].CounterTerrorists[0]
                },
                new ShotFired
                {
                    Round   = 2,
                    Shooter = TeamPlayersValues[1].CounterTerrorists[0]
                }
            };


            ProcessedData = new ProcessedData()
            {
                DemoInformation     = DemoInformation,
                SameFilename        = true,
                SameFolderStructure = true,
                ParseChickens       = true,
                FoldersToProcess    = new List <string>()
                {
                    "someFolder"
                },
                OutputRootFolder         = "outputFolder",
                tanookiStats             = tanookiStats,
                MatchStartValues         = MatchStartValues,
                SwitchSidesValues        = SwitchSidesValues,
                MessagesValues           = MessagesValues,
                TeamPlayersValues        = TeamPlayersValues,
                PlayerKilledEventsValues = PlayerKilledEventsValues,
                PlayerValues             = PlayerValues,
                WeaponValues             = WeaponValues,
                PenetrationValues        = PenetrationValues,
                BombsitePlantValues      = BombsitePlantValues,
                BombsiteExplodeValues    = BombsiteExplodeValues,
                BombsiteDefuseValues     = BombsiteDefuseValues,
                HostageRescueValues      = HostageRescueValues,
                HostagePickedUpValues    = HostagePickedUpValues,
                TeamValues           = TeamValues,
                RoundEndReasonValues = RoundEndReasonValues,
                RoundLengthValues    = RoundLengthValues,
                TeamEquipmentValues  = TeamEquipmentValues,
                GrenadeValues        = GrenadeValues,
                ChickenValues        = ChickenValues,
                ShotsFiredValues     = ShotsFiredValues,
                WriteTicks           = true
            };
        }
Example #17
0
        private async void UpdateResults(ImageAnalyzer img)
        {
            ProcessedData pd = new ProcessedData();

            pd.Location = "Area 1";

            if (img.AnalysisResult.Tags == null || !img.AnalysisResult.Tags.Any())
            {
                this.tagsGridView.ItemsSource = new[] { new { Name = "No tags" } };
            }
            else
            {
                this.tagsGridView.ItemsSource = img.AnalysisResult.Tags.Select(t => new { Confidence = string.Format("({0}%)", Math.Round(t.Confidence * 100)), Name = t.Name });
            }

            if (img.AnalysisResult.Description == null || !img.AnalysisResult.Description.Captions.Any(d => d.Confidence >= 0.2))
            {
                this.descriptionGridView.ItemsSource = new[] { new { Description = "Not sure what that is" } };
                pd.Report = "Not sure what that is";
            }
            else
            {
                this.descriptionGridView.ItemsSource = img.AnalysisResult.Description.Captions.Select(d => new { Confidence = string.Format("({0}%)", Math.Round(d.Confidence * 100)), Description = d.Text });
                pd.Report = img.AnalysisResult.Description.Captions[0].Text;
            }

            var celebNames = this.GetCelebrityNames(img);

            if (celebNames == null || !celebNames.Any())
            {
                this.celebritiesTextBlock.Text = "None";
            }
            else
            {
                this.celebritiesTextBlock.Text = string.Join(", ", celebNames.OrderBy(name => name));
            }

            if (img.AnalysisResult.Color == null)
            {
                this.colorInfoListView.ItemsSource = new[] { new { Description = "Not available" } };
            }
            else
            {
                this.colorInfoListView.ItemsSource = new[]
                {
                    new { Description = "Dominant background color:", Colors = new string[] { img.AnalysisResult.Color.DominantColorBackground } },
                    new { Description = "Dominant foreground color:", Colors = new string[] { img.AnalysisResult.Color.DominantColorForeground } },
                    new { Description = "Dominant colors:", Colors = img.AnalysisResult.Color.DominantColors },
                    new { Description = "Accent color:", Colors = new string[] { "#" + img.AnalysisResult.Color.AccentColor } }
                };
            }

            this.ocrToggle.IsEnabled = true;

            if (img.ImageUrl != null)
            {
                // Download - Start
                HttpClient client = new HttpClient();
                byte[]     buffer = await client.GetByteArrayAsync(img.ImageUrl);

                pd.Img = buffer;
                // Download - End
            }
            else if (img.Data != null)
            {
                pd.Img = img.Data;
            }

            HttpClient httpClient         = new HttpClient();
            MultipartFormDataContent form = new MultipartFormDataContent();

            form.Add(new ByteArrayContent(pd.Img, 0, pd.Img.Length), "img", "image.jpg");
            form.Add(new StringContent(pd.Location), "location");
            form.Add(new StringContent(pd.Report), "report");
            HttpResponseMessage response = await httpClient.PostAsync("http://192.168.43.46:8000/api/crime/uploadCrime", form);

            //HttpResponseMessage response = await httpClient.PostAsync("https://requestb.in/100adnv1", form);

            response.EnsureSuccessStatusCode();
            httpClient.Dispose();
            string sd = response.Content.ReadAsStringAsync().Result;
        }
Example #18
0
        public JsonResult ProceedAttenanceData(string Date)
        {
            AttenenceRepository ar = new AttenenceRepository();

            if (Session[Constances.UserId] != null)
            {
                DateTime Dateprocess = Date != "" ? Convert.ToDateTime(Date).Date : DateTime.Now.Date;

                // Monthly
                var Wage = ar.GetWAGESTYPE(Convert.ToInt32(WageType.Monthly));

                var shipmaster = ar.GetShiftMasterData(Convert.ToInt32(WageType.Monthly));

                var AttData = ar.GetAttenancedata(Dateprocess, Convert.ToInt32(WageType.Monthly));

                var Shiftstarttime = shipmaster.Select(x => x.InTime).FirstOrDefault();
                Shiftstarttime = Shiftstarttime.Add(Wage.Allowance);

                foreach (var at in AttData)
                {
                    ProcessedData p = new ProcessedData();
                    p.EmpCode        = Convert.ToInt32(at.EmployeeId);
                    p.Date           = Dateprocess;
                    p.ActualSalary   = at.ActualSalary;
                    p.AduitingSalary = at.AduitingSalary;
                    var Intime = at.InTime;

                    if (Intime > Shiftstarttime)
                    {
                        p.Status = "Late";
                    }

                    if (at.PunchRecords.EndsWith(","))
                    {
                        at.PunchRecords = at.PunchRecords.Substring(0, at.PunchRecords.Length - 1);
                    }

                    string[] PunchRecords = at.PunchRecords.Split(',');

                    if (PunchRecords.Length % 2 != 0)
                    {
                        p.Status = "Invalid Punch records";
                    }
                    else
                    {
                        TimeSpan ts = TimeSpan.Parse("00:00");
                        for (int i = 0; i < PunchRecords.Length; i++)
                        {
                            PunchRecords[i]     = PunchRecords[i].Substring(0, 5);
                            PunchRecords[i + 1] = PunchRecords[i + 1].Substring(0, 5);

                            if (TimeSpan.Parse(PunchRecords[i + 1]) > TimeSpan.Parse(PunchRecords[i]))
                            {
                                TimeSpan tsa = TimeSpan.Parse(PunchRecords[i + 1]).Subtract(TimeSpan.Parse(PunchRecords[i]));
                                ts = ts.Add(tsa);
                            }
                            else
                            {
                                TimeSpan day = TimeSpan.FromHours(24);
                                TimeSpan tsa = TimeSpan.Parse(PunchRecords[i + 1]).Add(day).Subtract(TimeSpan.Parse(PunchRecords[i]));
                                ts = ts.Add(tsa);
                            }
                            i++;
                        }
                        p.HoursWorked = ts;

                        if (ts.Hours >= 9)
                        {
                            p.ShiftCount = 1;
                        }
                        else if (Convert.ToDouble(ts.Hours + (Convert.ToDecimal(ts.Minutes) / 100)) > 4.5 && ts.Hours < 9)
                        {
                            p.ShiftCount = 0.5m;
                        }
                        else
                        {
                            p.ShiftCount = 0m;
                        }

                        p.Status = "";
                    }

                    ar.InsertProcessData(p);
                }
            }

            return(Json(true, JsonRequestBehavior.AllowGet));
        }
Example #19
0
        /// <summary>
        /// 写入内容到流中
        /// </summary>
        /// <param name="stream"></param>
        public override void WriteTo(Stream stream)
        {
            if (PostedFile.Count > 0 || ContentType == ContentType.FormData)
            {
                //写入普通区域
                foreach (var v in ProcessedData)
                {
                    if (v.Value == null)
                    {
                        continue;
                    }

                    var str = "--" + RequestBoundary + "\r\nContent-Disposition: form-data; name=\"" + v.Key + "\"\r\n\r\n";
                    stream.Write(Context.Request.Encoding.GetBytes(str));
                    if (!v.Value.IsNullOrEmpty())
                    {
                        stream.Write(Context.Request.Encoding.GetBytes(v.Value));
                    }
                    stream.Write(Context.Request.Encoding.GetBytes("\r\n"));
                }

                //写入文件
                PostedFile.ForEach(s => s.WriteTo(stream));
                var endingstr = "--" + RequestBoundary + "--";
                stream.Write(Context.Request.Encoding.GetBytes(endingstr));
            }
            else
            {
                stream.Write((ContentType == ContentType.FormUrlEncoded ? System.Text.Encoding.ASCII : Message.Encoding).GetBytes(ProcessedData.Where(s => s.Value != null).Select(s => s.Key + "=" + s.Value).Join("&")));
            }
        }
Example #20
0
        /// <summary>
        /// 异步将数据写入当前的请求流中
        /// </summary>
        /// <param name="asyncData"></param>
        public override void WriteToAsync(AsyncStreamProcessData asyncData)
        {
            base.WriteToAsync(asyncData);

            //异步写入的时候,如果没有文件,则一次性写入
            if (ContentType == ContentType.FormUrlEncoded)
            {
                asyncData.AsyncStreamWrite((ContentType == ContentType.FormUrlEncoded ? System.Text.Encoding.ASCII : Message.Encoding).GetBytes(ProcessedData.Where(s => s.Value != null).Select(s => s.Key + "=" + s.Value).Join("&")), false, null);
                return;
            }

            //否则先写入普通数据,再写入文件。
            byte[] textBuffer = null;
            using (var ms = new MemoryStream())
            {
                //写入普通区域
                foreach (var v in ProcessedData)
                {
                    if (v.Value == null)
                    {
                        continue;
                    }

                    var str = "--" + RequestBoundary + "\r\nContent-Disposition: form-data; name=\"" + v.Key + "\"\r\n\r\n";
                    ms.Write(Message.Encoding.GetBytes(str));
                    if (!v.Value.IsNullOrEmpty())
                    {
                        ms.Write(Message.Encoding.GetBytes(v.Value));
                    }
                    ms.Write(Message.Encoding.GetBytes("\r\n"));
                }
                ms.Close();
                textBuffer = ms.ToArray();
            }

            asyncData.AsyncStreamWrite(textBuffer, true, _ =>
            {
                _currentAsyncFileIndex = 0;

                if (AsyncData.Exception != null)
                {
                    return;
                }

                WriteFileAsync();
            });
        }
Example #21
0
 public void AddProcessedData(ProcessedData data)
 {
     _dataRepository.AddData(data);
 }
Example #22
0
 public void AddData(ProcessedData data)
 {
     _context.ProcessedData.Add(data);
 }
 protected virtual void SerializeDataAsQueryString()
 {
     SerializedDataString = ProcessedData.Select(s => s.Key + "=" + s.Value).Join("&");
 }
Example #24
0
 public void RemoveData(ProcessedData data)
 {
     _dataRepository.DeleteData(data.Id);
 }
Example #25
0
        /// <summary>
        /// Create the processed CSV file with required column
        /// </summary>
        /// <param name="taxiDatas"></param>
        /// <param name="path"></param>
        public static List <ProcessedData> CreateProcessedCSVFile(List <TaxiData> taxiDatas, string path)
        {
            List <ProcessedData> processedTaxiDatas = new List <ProcessedData>();

            foreach (var item in taxiDatas)
            {
                DateTime dateTime   = DateTime.Parse(item.lpep_pickup_datetime !, CultureInfo.GetCultureInfo("de-DE"));
                var      pickupTime = dateTime.ToString("HH:mm");
                Slot     result     = GetSlot(pickupTime);

                ProcessedData processedData = new ProcessedData();
                processedData.Date            = dateTime.Date;
                processedData.TimeSpan        = result.StartTime.ToString() + " - " + result.EndTime.ToString();
                processedData.Segment         = result.Segment;
                processedData.Passanger_count = item.passenger_count;
                processedTaxiDatas.Add(processedData);
            }

            var accumulatedPassangerData = processedTaxiDatas.GroupBy(c => new
            {
                c.Date,
                c.Segment
            }).Select(
                g => new
            {
                Date             = g.First().Date,
                TimeSpan         = g.First().TimeSpan,
                Segment          = g.First().Segment,
                Passsanger_Count = g.Sum(s => s.Passanger_count),
            }).AsEnumerable()
                                           .Cast <dynamic>();

            var           totalPassangerData = accumulatedPassangerData.ToList();
            StringBuilder csvcontent         = new StringBuilder();

            csvcontent.AppendLine("Pickup_Date,TimeSpan,Segment,Passenger_count");
            processedTaxiDatas.Clear();

            foreach (var taxiData in totalPassangerData)
            {
                processedTaxiDatas.Add(new ProcessedData {
                    Date = taxiData.Date, Passanger_count = taxiData.Passsanger_Count, Segment = taxiData.Segment, TimeSpan = taxiData.TimeSpan
                });
                var newLine = string.Format("{0},{1},{2},{3}", taxiData.Date, taxiData.TimeSpan, taxiData.Segment, taxiData.Passsanger_Count);
                csvcontent.AppendLine(newLine);
            }

            if (!String.IsNullOrEmpty(path))
            {
                // Delete the existing file to avoid duplicate records.
                if (File.Exists(path + "2021_Green_Processed.csv"))
                {
                    File.Delete(path + "2021_Green_Processed.csv");
                }

                // Save processed CSV data
                File.AppendAllText(path + "2021_Green_Processed.csv", csvcontent.ToString());
            }

            return(processedTaxiDatas);
        }
        private async Task <MemoryStream> ConvertToMemoryStreamAsync(ProcessedData processedData)
        {
            var converter = TypeDescriptor.GetConverter(typeof(ProcessedData));

            return(await Task.Run(() => converter.ConvertTo(processedData, typeof(MemoryStream)) as MemoryStream));
        }
Example #27
0
        private static ProcessedData ExtractFunctions(string regExp)
        {
            ProcessedData pd = new ProcessedData();

            //look for literal text functions first
            while (regExp.Contains("(???<")) //while we have a function
            {
                int nameEnd = -1, depth = 0, start = regExp.IndexOf("(???<"), end = start;

                //find the end of the function
                do //look for ) matching the starting (
                {
                    if (nameEnd == -1 && regExp[end] == '>')
                    {
                        nameEnd = end;
                    }

                    if (regExp[end] == '(')
                    {
                        depth++;
                    }

                    if (regExp[end] == ')' && regExp[end - 1] != '\\')
                    {
                        depth--;
                    }

                    end++;
                } while (!(regExp[end - 1] == ')' && depth == 0));

                if (pd.functionList == null)
                {
                    pd.functionList = new List <RegExFunction>();
                }

                RegExFunction rxf = new RegExFunction();

                rxf.name        = regExp.Substring(start + 5, nameEnd - (start + 5));
                rxf.regExp      = regExp.Substring(nameEnd + 2, (end - 2) - (nameEnd + 2));
                rxf.literalText = true;

                pd.functionList.Add(rxf);

                regExp = regExp.Substring(0, start) + regExp.Substring(end); //remove the function definition
            }

            while (regExp.Contains("(??<")) //while we have a function
            {
                int nameEnd = -1, depth = 0, start = regExp.IndexOf("(??<"), end = start;

                //find the end of the function
                do //look for ) matching the starting (
                {
                    if (nameEnd == -1 && regExp[end] == '>')
                    {
                        nameEnd = end;
                    }

                    if (regExp[end] == '(')
                    {
                        depth++;
                    }

                    if (regExp[end] == ')')
                    {
                        depth--;
                    }

                    end++;
                } while(!(regExp[end - 1] == ')' && depth == 0));

                if (pd.functionList == null)
                {
                    pd.functionList = new List <RegExFunction>();
                }

                RegExFunction rxf = new RegExFunction();

                rxf.name   = regExp.Substring(start + 4, nameEnd - (start + 4));
                rxf.regExp = regExp.Substring(nameEnd + 1, (end - 1) - (nameEnd + 1));

                pd.functionList.Add(rxf);

                regExp = regExp.Substring(0, start) + regExp.Substring(end); //remove the function definition
            }

            pd.regExp = regExp; //the regex with the function definitions removed

            return(pd);
        }
Example #28
0
 public void UpdateData(ProcessedData data)
 {
     _context.Entry(data).State = EntityState.Modified;
 }
 public void AddData(ProcessedData data)
 {
     _context.ProcessedData.Add(data);
     //TODO remove unused code
     //_context.SaveChanges();
 }