예제 #1
0
    /// <summary>
    /// try's to get candidate setts from the active letter sett by
    /// reducing it with different words, the extent of the trying
    /// is hardcoded
    ///
    /// if a set is found the active letter sett is automatically changed
    /// </summary>
    /// <returns>a list of candidate sets, can be empty if none are found</returns>
    List <SetValuePair> GetFromReduced()
    {
        int activeSetLen   = this.activeLetterSet.Count;
        int tmpRedWordSize = this.reduceWordSizeMin;

        string[] activeAr = this.activeLetterSet.ToArray();

        List <SetValuePair> possibleLetterSetts = new List <SetValuePair>();

        var rand = new System.Random();

        while (true)
        {
            if (tmpRedWordSize >= activeSetLen - this.startWordSearchAt || tmpRedWordSize >= this.reduceWordSizeMax)
            {
                return(possibleLetterSetts);
            }

            List <SetValuePair> possibleReductWords = this.GetPossibleReductions(tmpRedWordSize);
            int tmpCount = possibleReductWords.Count;
            for (int i = 0; i < tmpCount; i++)
            {
                int          currentTest = rand.Next(0, possibleReductWords.Count);
                SetValuePair posR        = possibleReductWords[currentTest];

                List <String> tmpActiveSequence = WUArrays.RemoveAllAFromB(posR.letter_sett, activeAr);
                tmpActiveSequence.Sort();

                List <SetValuePair> possibleSetts = this.FindNextLetterSetts(tmpActiveSequence.ToArray());
                if (possibleSetts.Count > 0)
                {
                    //print($"Reduced letter sett by {tmpRedWordSize} caracters");
                    this.activeLetterSet = tmpActiveSequence;
                    return(possibleSetts);
                }

                possibleReductWords.RemoveAt(currentTest);
            }

            tmpRedWordSize += 1;
        }
    }
예제 #2
0
    /// <summary>
    /// Generates a letter that will in combination with the
    /// Earlier generated letters for on or more words*
    ///
    /// *if the algorithm cant find or reduce down to get a letter a random one will be picked
    /// </summary>
    /// <returns> the generated letter</returns>
    public String GenerateLetter()
    {
        List <SetValuePair> nextUsedSets = new List <SetValuePair>();

        string[] activeAr = this.activeLetterSet.ToArray();

        if (this.activeLetterSet.Count >= this.startWordSearchAt)
        {
            // try normal generation
            nextUsedSets = this.FindNextLetterSetts(activeAr);

            // no normal found try find from reduced
            if (nextUsedSets.Count == 0)
            {
                nextUsedSets = this.GetFromReduced();
            }

            if (nextUsedSets.Count > 0)
            {
                activeAr = this.activeLetterSet.ToArray(); // if it has been reduced in reduce
                var          rand     = new System.Random();
                int          val      = rand.Next(0, nextUsedSets.Count);
                SetValuePair usedSett = nextUsedSets[val];

                String nextLetter = WUArrays.RemoveAllAFromB(activeAr, usedSett.letter_sett)[0];

                this.AddLetter(nextLetter);
                return(nextLetter);
            }
        }

        // ether the letter search yielded no results or the word was to short
        String l = this.letterFrequency.GetLetterByFrequency();

        this.AddLetter(l);
        return(l);
    }
예제 #3
0
        public async Task <IActionResult> OnPostSplitSetCableAsync(string id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }


            // 0:10, 1:5, 2:5
            string processedRequest = Input.SplitSetValue.Replace(" ", "");

            string[] SetValuePairs = processedRequest.Split(',');

            {
                int combinedValues = 0;
                foreach (var SetValuePair in SetValuePairs)
                {
                    combinedValues += int.Parse(SetValuePair.Split(':')[1]);
                }
                var record = _db.VTMagazyn.FirstOrDefault(c =>
                                                          c.Wiazka == Input.Wiazka &&
                                                          c.KodCiety == Input.KodCiety &&
                                                          c.DataDostawy.Date == Input.DeliveryDate.Date &&
                                                          c.NumerKompletu == Input.SetID);

                if (combinedValues != record.SztukiZeskanowane)
                {
                    ModelState.AddModelError("Niepoprawana ilość", " ilość w kompletach nie zgadza się z iloscią do rozbicia");
                    return(Page());
                }
            }

            var records = await _db.VTMagazyn.Where(c =>
                                                    c.Wiazka == Input.Wiazka &&
                                                    c.KodCiety == Input.KodCiety &&
                                                    c.DataDostawy.Date == Input.DeliveryDate.Date).ToListAsync();

            var deliveryRecords = await _db.Dostawa.IgnoreQueryFilters().AsNoTracking().Include(c => c.Technical).Where(c =>
                                                                                                                        c.Technical.Wiazka == Input.Wiazka &&
                                                                                                                        c.Data.Date == Input.DeliveryDate.Date).ToListAsync();

            foreach (var SetValuePair in SetValuePairs)
            {
                int Set   = int.Parse(SetValuePair.Split(':')[0]);
                int Value = int.Parse(SetValuePair.Split(':')[1]);

                var record = records.FirstOrDefault(c => c.NumerKompletu == Set);

                if (record != null)
                {
                    int original = record.SztukiZeskanowane;
                    record.SztukiZeskanowane = Value;
                    UpdateWiazkaOnChange(record, original);

                    //_db.Update(record);
                    await _db.SaveChangesAsync();
                }
                else if (Value != 0)
                {
                    int declaredValue = GetPossibleDeclaredValue(
                        new ScannedCode {
                        Wiazka = Input.Wiazka, dataDostawyOld = Input.DeliveryDate
                    },
                        records, deliveryRecords, Set);
                    if (declaredValue == 0)
                    {
                        declaredValue = Value;
                    }

                    AddToVT(Set, Value, declaredValue, Input.dokumentDostawy, Input.DeliveryDate);
                    checkComplete(Set, Input.Wiazka, Input.DeliveryDate);
                }
            }

            return(Page());
        }