Beispiel #1
0
        private static void DrawRow(ExcelWorksheet ws, CalculationItem item, int iRow)
        {
            var iColumn = 1;

            ws.Cells[iRow, iColumn++].Value         = item.ClientNic;
            ws.Cells[iRow, iColumn++].Value         = item.DisplayNumber;
            ws.Cells[iRow, iColumn++].Value         = item.Factory;
            ws.Cells[iRow, iColumn++].Value         = item.Mark;
            ws.Cells[iRow, iColumn++].Value         = item.ClassId.HasValue ? item.ClassId.Value.ToLocalString() : "";
            ws.Cells[iRow, iColumn++].Value         = item.Count;
            ws.Cells[iRow, iColumn++].Value         = item.Weight;
            ws.Cells[iRow, iColumn++].Value         = item.SenderRate;
            ws.Cells[iRow, iColumn].Style.Font.Bold = true;
            ws.Cells[iRow, iColumn++].Value         = item.TotalSenderRate;
            ws.Cells[iRow, iColumn++].Value         = item.Invoice;
            ws.Cells[iRow, iColumn++].Value         = item.Value;
            ws.Cells[iRow, iColumn++].Value         = item.TariffPerKg;
            ws.Cells[iRow, iColumn].Style.Font.Bold = true;
            ws.Cells[iRow, iColumn++].Value         = item.TotalTariffCost;
            ws.Cells[iRow, iColumn++].Value         = item.ScotchCost;
            ws.Cells[iRow, iColumn++].Value         = item.InsuranceCost;
            ws.Cells[iRow, iColumn++].Value         = item.FactureCost;
            ws.Cells[iRow, iColumn++].Value         = item.FactureCostEx;
            ws.Cells[iRow, iColumn++].Value         = item.PickupCost;
            ws.Cells[iRow, iColumn++].Value         = item.TransitCost;
            ws.Cells[iRow, iColumn].Style.Font.Bold = true;
            ws.Cells[iRow, iColumn].Value           = item.Profit;
        }
    public void TestClassifyPeptideHit()
    {
      List<IIdentifiedSpectrum> spectra = new List<IIdentifiedSpectrum>();
      spectra.Add(new IdentifiedSpectrum() { Rank = 1 });
      spectra.Add(new IdentifiedSpectrum() { Rank = 1 });
      spectra.Add(new IdentifiedSpectrum() { Rank = 2 });
      spectra.Add(new IdentifiedSpectrum() { Rank = 2 });

      new IdentifiedPeptide(spectra[0]) { Sequence = "SE*Q" };
      new IdentifiedPeptide(spectra[1]) { Sequence = "SEQ" };
      new IdentifiedPeptide(spectra[2]) { Sequence = "SEQSEQ" };
      new IdentifiedPeptide(spectra[3]) { Sequence = "SEQSEQSEQ" };

      CalculationItem item = new CalculationItem()
      {
        Peptides = spectra.ConvertAll(m => m.Peptide).ToList()
      };


      item.ClassifyPeptideHit(m => m.Spectrum.Rank.ToString(), new string[] { "1", "2" });

      Assert.AreEqual(2, item.Classifications.Count);
      Assert.AreEqual(2, item.Classifications["1"].PeptideCount);
      Assert.AreEqual(1, item.Classifications["1"].UniquePeptideCount);
      Assert.AreEqual(2, item.Classifications["2"].PeptideCount);
      Assert.AreEqual(2, item.Classifications["2"].UniquePeptideCount);
    }
Beispiel #3
0
        private void btnTo_Click(object sender, EventArgs e)
        {
            //When adding a new calc field, make sure to save the previously selected field (if any)
            //then add the new item to the selected field list

            if (lbFields.SelectedIndex != -1)
            {
                string[] arr = lbFields.SelectedItem.ToString().Split('.');

                string aa = "";

                foreach (string a in arr)
                {
                    if (aa == "")
                    {
                        aa = Program.BraketizeKeywords(a);
                    }
                    else
                    {
                        aa += "." + Program.BraketizeKeywords(a);
                    }
                }


                lbSelFields.Items.Add(aa);

                //Update current items info
                if (lbSelFields.SelectedIndex != -1)
                {
                    CalculationItem item = SelectedFields[lbSelFields.SelectedIndex];

                    //Get the field & table name
                    string[] fieldWithTable = lbSelFields.SelectedItem.ToString().Split('.');

                    item.CalculationTable = fieldWithTable[0];
                    item.CalculationField = fieldWithTable[1];

                    SelectedFields.RemoveAt(lbSelFields.SelectedIndex);
                    SelectedFields.Insert(lbSelFields.SelectedIndex, item);
                }

                //Initialize & Add the new item to the SelectedFields List
                CalculationItem newItem = new CalculationItem();
                newItem.CalculationType = GetSelectedRadioCalc();

                string[] newFieldWithTable = lbFields.SelectedItem.ToString().Split('.');
                newItem.CalculationTable = newFieldWithTable[0];

                // make sure the field name does not have spaces if so bracket it

                string nfwt = Program.BraketizeKeywords(newFieldWithTable[1]);

                newItem.CalculationField = nfwt;

                SelectedFields.Add(newItem);
                lbSelFields.SelectedIndex = lbSelFields.Items.Count - 1;
            }

            RegenClause();
        }
Beispiel #4
0
 public async Task StoreAsync(CalculationItem item)
 {
     if (item != null)
     {
         await _context.SaveAsync(item);
     }
 }
Beispiel #5
0
        public static CalculationItem DeserializeCalculationItem(JObject json, CalculationGroupTable calculationGroupTable)
        {
            var tom = TOM.JsonSerializer.DeserializeObject <TOM.CalculationItem>(json.ToString());

            tom.Name = calculationGroupTable.CalculationItems.GetNewName(tom.Name);

            var calculationItem = CalculationItem.CreateFromMetadata(calculationGroupTable.CalculationGroup, tom);

            return(calculationItem);
        }
Beispiel #6
0
        //Text Box Events

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (lbSelFields.SelectedIndex != -1)
            {
                CalculationItem selectedItem = SelectedFields[lbSelFields.SelectedIndex];
                selectedItem.CalculationAlias = txtAlias.Text;
                SelectedFields.RemoveAt(lbSelFields.SelectedIndex);
                SelectedFields.Insert(lbSelFields.SelectedIndex, selectedItem);
                RegenClause();
            }
        }
Beispiel #7
0
        public static CalculationItem DeserializeCalculationItem(JObject json, CalculationGroupTable calculationGroupTable)
        {
            var tom = TOM.JsonSerializer.DeserializeObject <TOM.CalculationItem>(json.ToString(Formatting.None));

            tom.Name    = calculationGroupTable.CalculationItems.GetNewName(tom.Name);
            tom.Ordinal = calculationGroupTable.CalculationItems.Any(i => i.Ordinal != -1) ? calculationGroupTable.CalculationItems.Max(i => i.Ordinal) + 1 : -1;

            var calculationItem = CalculationItem.CreateFromMetadata(calculationGroupTable.CalculationGroup, tom);

            return(calculationItem);
        }
Beispiel #8
0
 private void CalculateItem(CalculationItem item)
 {
     foreach (var pr in calculatedProducts)
     {
         var calcValue = new CalculatedValue
         {
             Item  = item,
             Value = CalculateValue(ParseExpression(pr.Product, item, pr.CalculatedValues), item.NeedRound == 1)
         };
         pr.CalculatedValues.Add(calcValue);
     }
 }
Beispiel #9
0
 private void UpdateCalculationType()
 {
     if (lbSelFields.SelectedIndex != -1 && lbSelFields.Items.Count > 0)
     {
         int             i  = lbSelFields.SelectedIndex;
         CalculationItem ci = SelectedFields[i];
         ci.CalculationType = GetSelectedRadioCalc();
         SelectedFields.RemoveAt(i);
         SelectedFields.Insert(i, ci);
         RegenClause();
     }
 }
Beispiel #10
0
 public void AddCalculationItem(CalculationGroup calcGroup, Tom.CalculationItem tomCalcItem)
 {
     Dax.Metadata.CalculationItem calcItem = new CalculationItem(calcGroup)
     {
         ItemExpression         = DaxExpression.GetExpression(tomCalcItem.Expression),
         FormatStringDefinition = DaxExpression.GetExpression(tomCalcItem.FormatStringDefinition?.Expression),
         ItemName                 = new Dax.Metadata.DaxName(tomCalcItem.Name),
         State                    = tomCalcItem.State.ToString(),
         ErrorMessage             = tomCalcItem.ErrorMessage,
         FormatStringState        = tomCalcItem.FormatStringDefinition?.State.ToString(),
         FormatStringErrorMessage = tomCalcItem.FormatStringDefinition?.ErrorMessage
     };
     calcGroup.CalculationItems.Add(calcItem);
 }
Beispiel #11
0
        private void GetSum(CalculationItem item)
        {
            decimal ret = 0;

            foreach (var i in calculatedProducts)
            {
                foreach (var val in i.CalculatedValues.Where(x => x.Item.ID == item.ID))
                {
                    ret += val.Value;
                }
            }

            ItemSumList.Add(new ItemSum {
                Item = item, Value = ret
            });
        }
Beispiel #12
0
        public CalculationItemForm(CalculationSettings sender, int type, CalculationItem editItem)
        {
            InitializeComponent();
            _sender = sender;
            _type   = type;
            if (_type == 2)
            {
                _editModel        = editItem;
                checkBox1.Checked = _editModel.WithSum == 1;
                checkBox2.Checked = _editModel.NeedRound == 1;
            }

            LoadLists();
            tb_name.DataBindings.Add("Text", _editModel, "ItemName");
            tb_value.DataBindings.Add("Text", _editModel, "Expression");
        }
        private string SaveInformations(InputData input, CalculationResult result)
        {
            CalculationItem item = new CalculationItem
            {
                Id          = Guid.NewGuid().ToString(),
                Name        = input.Name,
                Age         = input.Age,
                Height      = input.Height,
                Weight      = input.Weight,
                BMI         = result.BMI,
                Description = result.Description.ToString()
            };

            _store.StoreAsync(item);

            return(item.Id);
        }
    public void TestClassifyPeptideHit2()
    {
      var ir = new SequestResultTextFormat().ReadFromFile(@"../../../data/TestDistributionOption.noredundant");

      CalculationItem item = new CalculationItem()
      {
        Peptides = ir[0][0].GetDistinctPeptides()
      };
      item.ClassifyPeptideHit(m => "G1");
      Assert.AreEqual(1360, item.Classifications["G1"].PeptideCount);
      Assert.AreEqual(24, item.Classifications["G1"].UniquePeptideCount);

      item.Peptides = ir[1][0].GetDistinctPeptides();
      item.ClassifyPeptideHit(m => "G1");
      Assert.AreEqual(5, item.Classifications["G1"].PeptideCount);
      Assert.AreEqual(1, item.Classifications["G1"].UniquePeptideCount);
    }
        public string Post([FromBody] CalculationItem item)
        {
            double I2 = 0;

            try
            {
                if (!ModelState.IsValid)
                {
                    return("Model is invalid");
                }

                I2 = CalculatePower(item);
            }
            catch (Exception e)
            {
                return(e.Message);
            }


            return(string.Format("{{\"I2\":{0}}}", I2.ToString()));;
        }
Beispiel #16
0
        private void lbSelFields_MouseClicked(object sender, EventArgs e)
        {
            //Get the new index & show the selected items values
            if (lbSelFields.SelectedIndex != -1)
            {
                int             i  = lbSelFields.SelectedIndex;
                CalculationItem ci = SelectedFields[i];
                txtAlias.Text = ci.CalculationAlias;

                switch (ci.CalculationType)
                {
                case "AVG(":
                    rbAverage.Checked = true;
                    break;

                case "COUNT(":
                    rbCount.Checked = true;
                    break;

                case "COUNT DISTINCT(":
                    rbDistinctCount.Checked = true;
                    break;

                case "MAX(":
                    rbMaximum.Checked = true;
                    break;

                case "MIN(":
                    rbMinimum.Checked = true;
                    break;

                case "SUM(":
                    rbSum.Checked = true;
                    break;
                }
            }
        }
Beispiel #17
0
        private string ParseExpression(ImportedProduct product, CalculationItem item, List <CalculatedValue> caclulatedValues)
        {
            Dictionary <string, string> replace = new Dictionary <string, string>();


            string itemPattern = @"item\[\d+\]";

            foreach (Match match in Regex.Matches(item.Expression, itemPattern))
            {
                string pattern = @"\d+";

                var itemId = Convert.ToInt32(Regex.Match(match.Value, pattern).ToString());

                var itemValue = caclulatedValues.FirstOrDefault(x => x.Item.ID == itemId);
                if (itemValue != null)
                {
                    if (!replace.ContainsKey(match.Value))
                    {
                        replace.Add(match.Value, itemValue.Value.ToString());
                    }
                }
            }

            string constantPattern = @"constant\[\d+\]";

            foreach (Match match in Regex.Matches(item.Expression, constantPattern))
            {
                string pattern    = @"\d+";
                var    constantId = Convert.ToInt32(Regex.Match(match.Value, pattern).ToString());

                var constantValue = _usedConstatns.FirstOrDefault(x => x.ID == constantId);
                if (constantValue != null)
                {
                    if (!replace.ContainsKey(match.Value))
                    {
                        replace.Add(match.Value, constantValue.Value.ToString());
                    }
                }
            }

            string sumPattern = @"sum\[\d+\]";

            foreach (Match match in Regex.Matches(item.Expression, sumPattern))
            {
                string pattern = @"\d+";

                var itemId   = Convert.ToInt32(Regex.Match(match.Value, pattern).ToString());
                var sumValue = ItemSumList.FirstOrDefault(x => x.Item.ID == itemId);
                if (sumValue != null)
                {
                    if (!replace.ContainsKey(match.Value))
                    {
                        replace.Add(match.Value, sumValue.Value.ToString());
                    }
                }
            }

            string dynamicPattern = @"dynamic\[\d+\]";

            foreach (Match match in Regex.Matches(item.Expression, dynamicPattern))
            {
                string pattern = @"\d+";

                var dynamicId    = Convert.ToInt32(Regex.Match(match.Value, pattern).ToString());
                var dynamicValue = CalculatedDynamics.FirstOrDefault(x => x.Dynamic.ID == dynamicId);
                if (dynamicValue != null)
                {
                    if (!replace.ContainsKey(match.Value))
                    {
                        replace.Add(match.Value, dynamicValue.Value.ToString());
                    }
                }
            }


            replace.Add("price", product.Product.Price.ToString());
            replace.Add("count", product.Count.ToString());
            replace.Add("TNVEDCode", product.TNVEDCode.ToString());
            replace.Add("TNVEDValue", product.TNVEDValue.ToString());
            replace.Add("Additional", product.Additional.ToString());
            var ret = item.Expression;

            foreach (var i in replace)
            {
                ret = ret.Replace(i.Key, i.Value);
            }
            return(ret);
        }
Beispiel #18
0
        public void AddCalculationGroups()
        {
            try
            {
                using (Server server = new Server())
                {
                    server.Connect(_ConnectionString);
                    Model dekstopModel = server.Databases[_Model].Model;
                    foreach (Table modeltable in dekstopModel.Tables)
                    {
                        //Did we already add a calc group?
                        if (modeltable.Name == _groupName)
                        {
                            throw new ModelException("This model already contains a table with this name.");
                        }
                    }

                    CalculationGroup calculationGroup = new CalculationGroup()
                    {
                        Description = "None",
                        Precedence  = _calcgroups,
                    };

                    foreach (CalculationGroupItem _calculationGroupItem in _calculationGroupItems)
                    {
                        CalculationItem calculationItem = new CalculationItem()
                        {
                            Name       = _calculationGroupItem.Name,
                            Expression = _calculationGroupItem.Expression,
                            Ordinal    = _calculationGroupItem.Ordinal,
                        };

                        if (_calculationGroupItem.FormatString.Length > 0)
                        {
                            calculationItem.FormatStringDefinition = new FormatStringDefinition()
                            {
                                Expression = _calculationGroupItem.FormatString
                            };
                        }

                        calculationGroup.CalculationItems.Add(calculationItem);
                    }

                    Partition partition = new Partition()
                    {
                        Name   = "Partition For " + _groupName,
                        Source = new CalculationGroupSource()
                    };

                    Table table = new Table()
                    {
                        Name             = _groupName,
                        CalculationGroup = calculationGroup
                    };

                    table.Columns.Add(new DataColumn()
                    {
                        Name     = _columnName,
                        DataType = DataType.String
                    });

                    var model = dekstopModel;
                    table.Partitions.Add(partition);
                    model.Tables.Add(table);
                    table.RequestRefresh(RefreshType.Full);
                    model.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                //throw it again
                throw ex;
            }
        }
Beispiel #19
0
        private void PopulateExistingCalculations(string[] meta)
        {
            List <CalculationItem> allMeta = new List <CalculationItem>();
            int i = 0;

            //meta should always be a multiple of 4, but add check to avoid error
            while (i < meta.Length && (i % 4 == 0))
            {
                CalculationItem ci = new CalculationItem();

                ci.CalculationType  = meta[i++];
                ci.CalculationAlias = meta[i++];
                ci.CalculationField = meta[i++];
                ci.CalculationTable = meta[i++];

                allMeta.Add(ci);
            }

            SelectedFields = allMeta;

            //add each previously selected calculation field to the selected list box
            foreach (CalculationItem c in allMeta)
            {
                lbSelFields.Items.Add(c.CalculationTable + "." + c.CalculationField);
            }

            //Automatically select the first item in lbSelFields
            if (lbSelFields.Items.Count > 0)
            {
                lbSelFields.SelectedIndex = 0;
                CalculationItem ci = SelectedFields[0];
                txtAlias.Text = ci.CalculationAlias;

                switch (ci.CalculationType)
                {
                case "AVG(":
                    rbAverage.Checked = true;
                    break;

                case "COUNT(":
                    rbCount.Checked = true;
                    break;

                case "COUNT DISTINCT(":
                    rbDistinctCount.Checked = true;
                    break;

                case "MAX(":
                    rbMaximum.Checked = true;
                    break;

                case "MIN(":
                    rbMinimum.Checked = true;
                    break;

                case "SUM(":
                    rbSum.Checked = true;
                    break;

                case "VAR(":
                    rbVar.Checked = true;
                    break;

                case "VARP(":
                    rbVarP.Checked = true;
                    break;

                case "STDEV(":
                    rbStDev.Checked = true;
                    break;

                case "STDEVP(":
                    rbStDevP.Checked = true;
                    break;
                }
            }

            RegenClause();
        }
 private static double CalculatePower(CalculationItem item)
 {
     return(((item.P * Math.Sqrt(3)) - (item.U1 * item.I1) - (item.U3 * item.I3)) / item.U2);
 }