// ------------------------------------------------------ //public void SetMeanDischarge_CalcEstMeanVars() //{ // // Calculate MeanDischarge and MeanEstVel for Estuaries // double N; // double DateIndex; // double SumEstVel; // double SumDisch; // double TTPres; // TSalinity TS; // N = 0; // TTPres = TPresent; // TS = GetStatePointer(AllVariables.Salinity, T_SVType.StV, T_SVLayer.WaterCol); // SumEstVel = 0; // SumDisch = 0; // DateIndex = TimeIndex - 1; // do // { // DateIndex = DateIndex + 1; // N = N + 1; // TPresent = DateIndex; // CalculateLoad(DateIndex); // TS.CalculateLoad(DateIndex); // Location.Discharge[VerticalSegments.Epilimnion] = UpperOutflow(); // SumEstVel = SumEstVel + Velocity(0, 0, false); // SumDisch = SumDisch + Location.Discharge[VerticalSegments.Epilimnion]; // } while (!(((DateIndex - 365) >= TimeIndex) || (DateIndex >= SetupRec.LastDay))); // MeanDischarge = SumDisch / N; // MeanEstVel = SumEstVel / N; // TPresent = TTPres; // CalculateLoad(TimeIndex); // // reset TVolume values // TS.CalculateLoad(TimeIndex); // Location.Discharge[VerticalSegments.Epilimnion] = UpperOutflow(); //} // ------------------------------------------------------ public double SetMeanDischarge_CalcDynamicMV(ref DateTime TimeIndex) { double result; // Calculates the volume for every time step then averages over a year DateTime DateIndex; double N; double DynamVol; double SumVol; SumVol = 0; DynamVol = State; N = 0; DateIndex = TimeIndex.AddDays(-1); do { DateIndex.AddDays(1); N = N + 1; CalculateLoad(DateIndex); DynamVol = DynamVol + InflowLoad - DischargeLoad - Evaporation(); // handle dynamic evaporation properly SumVol = SumVol + DynamVol; } while (!((DateIndex.AddDays(-365) >= TimeIndex) || (DateIndex >= AQTSeg.PSetup.LastDay))); result = SumVol / N; if (result < 0) { result = 0; } CalculateLoad(TimeIndex); // reset TVolume values return(result); }
} //TVolume.Derivative // ------------------------------------------------------ public void SetMeanDischarge_AverageVolumeLoads(ref DateTime TimeIndex, ref double AverageDischargeLoad, ref double AverageInflowLoad) { DateTime DateIndex; double N; double Sum_Dl; double Sum_IL; Sum_Dl = 0; Sum_IL = 0; N = 0; DateIndex = TimeIndex.AddDays(-1); do { DateIndex = DateIndex.AddDays(1); N = N + 1; CalculateLoad(DateIndex); Sum_Dl = Sum_Dl + DischargeLoad; Sum_IL = Sum_IL + InflowLoad; } while (!((DateIndex.AddDays(-365) >= TimeIndex) || (DateIndex >= AQTSeg.PSetup.LastDay))); AverageDischargeLoad = Sum_Dl / N; AverageInflowLoad = Sum_IL / N; CalculateLoad(TimeIndex); // reset TVolume values }
private int GetIndexOfValue(DateTime Time) { if (Time <= StartTime) { return(0); } if (Time >= EndTime) { return(Count - 1); } int index = 0; if (DateIndex.TryGetValue(Time.Date, out index)) { while (index < Count - 2 && Items[index + 1].Time <= Time) { index++; } } else { while (Items[index].Time < Time) { index++; } } return(index); }
public void Test_Date_DateIndexSetter_BadFormat_SemanticError() { //Arrange var Date = new Date("1974-25-25"); DateIndex Index = new DateIndex(); //Act ActualValueDelegate <DateIndex> testDelegate = () => IndexSetterFactory.Create(typeof(DateIndex)).Set(Date, Index) as DateIndex; //Assert Assert.That(testDelegate, Throws.TypeOf <FormatException>()); }
public void Test_Date_DateIndexSetter_GoodFormat_Year() { //Arrange var Date = new Date("1974"); DateIndex Index = new DateIndex(); //Act IndexSetterFactory.Create(typeof(DateIndex)).Set(Date, Index); //Assert Assert.AreEqual(19740000, Index.Date); }
// ------------------------------------------------------ public double SetMeanDischarge_CalcKnownValueMD(ref DateTime TimeIndex, ref double MV) { double result; // Calculates the discharge for every time step then averages over a year // Given that KnownValLoad - State = Inflow - Discharge - Evap // and that for each day, State should = KnownValLoad(T-1) then // Discharge = Inflow - KnownValLoad + KnownValLoad(T-1) - Evap DateTime DateIndex; double N; double KnownVal_Tminus1; double Sum_Disch; double SumVol; Sum_Disch = 0; SumVol = 0; KnownVal_Tminus1 = InitialCond; N = 0; DateIndex = TimeIndex.AddDays(-1); do { DateIndex = DateIndex.AddDays(1); N = N + 1; CalculateLoad(DateIndex); Sum_Disch = Sum_Disch + InflowLoad - KnownValueLoad + KnownVal_Tminus1 - Evaporation(); // handle dynamic evaporation properly KnownVal_Tminus1 = KnownValueLoad; SumVol = SumVol + KnownValueLoad; } while (!(((DateIndex.AddDays(-365)) >= TimeIndex) || (DateIndex >= AQTSeg.PSetup.LastDay))); result = Sum_Disch / N; MV = SumVol / N; if (result < 0) { result = 0; } CalculateLoad(TimeIndex); // reset TVolume values return(result); }
protected int CompareDates(DateIndex x, DateIndex y) { return (x.date.CompareTo(y.date)); }
protected bool WithinMouseRange(DateIndex target) { return ((target.date >= startMouseTime) && (target.date <= endMouseTime)); }
protected bool WithinGraphRange(DateIndex target) { return ((target.date >= startTime) && (target.date <= endTime)); }
public ActionResult _AjaxLoadingDateIndex(string text, string dateType, bool? includeBlankOption) { IList<DateIndex> dateIndexList = new List<DateIndex>(); if (string.IsNullOrEmpty(dateType)) { return new JsonResult { Data = new SelectList(dateIndexList, "Code", "Description") }; } DateTime datetimeNow = DateTime.Now; if (text.Length > 4) { string[] dateArray = text.Split('-'); string yyyy = dateArray[0]; string MM = dateArray.Length > 1 ? dateArray[1] : "01"; int mm = 1; int.TryParse(MM, out mm); MM = mm < 1 ? "01" : mm.ToString("D2"); if (dateType == ((int)com.Sconit.CodeMaster.TimeUnit.Week).ToString()) { MM = mm > 52 ? "52" : mm.ToString("D2"); try { datetimeNow = com.Sconit.Utility.DateTimeHelper.GetWeekIndexDateFrom(yyyy + "-" + MM); } catch (Exception) { datetimeNow = DateTime.Now; } } else { MM = mm > 12 ? "12" : mm.ToString("D2"); string dd = "01"; DateTime.TryParse(yyyy + "-" + MM + "-" + dd, out datetimeNow); } } if (dateType == ((int)com.Sconit.CodeMaster.TimeUnit.Week).ToString()) { string currentWeekOfYear = com.Sconit.Utility.DateTimeHelper.GetWeekOfYear(datetimeNow); string[] wky = currentWeekOfYear.Split('-'); int yearIndex = int.Parse(wky[0]); int weekIndex = int.Parse(wky[1]); var dateFrom = Utility.DateTimeHelper.GetWeekIndexDateFrom(currentWeekOfYear); dateFrom = dateFrom.AddDays(-1); for (int i = 0; i < 30; i++) { DateIndex dateIndex = new DateIndex(); if (weekIndex <= 0) { dateIndex.Code = (yearIndex - 1).ToString(); dateIndex.Code += "-" + (52 + weekIndex).ToString("D2"); } else if (weekIndex > 52) { dateIndex.Code = (yearIndex + 1).ToString(); dateIndex.Code += "-" + (weekIndex - 52).ToString("D2"); } else { dateIndex.Code = yearIndex.ToString(); dateIndex.Code += "-" + weekIndex.ToString("D2"); } var str = new StringBuilder(dateIndex.Code); str.Append("("); dateFrom = dateFrom.AddDays(1); str.Append(dateFrom.ToString("MM-dd")); str.Append(" -> "); dateFrom = dateFrom.AddDays(6); str.Append(dateFrom.ToString("MM-dd")); str.Append(")"); dateIndex.Description = str.ToString(); dateIndexList.Add(dateIndex); weekIndex++; } } else { string currentMonthOfYear = datetimeNow.ToString("yyyy-MM-dd"); string[] wky = currentMonthOfYear.Split('-'); int yearIndex = int.Parse(wky[0]); int monthIndex = int.Parse(wky[1]); if (monthIndex == 12) { monthIndex = 1; ++yearIndex; } for (int i = 0; i < 30; i++) { DateIndex newMonthOfYear = new DateIndex(); newMonthOfYear.Code = yearIndex + "-" + monthIndex.ToString("D2"); newMonthOfYear.Description = newMonthOfYear.Code; dateIndexList.Add(newMonthOfYear); if (monthIndex == 12) { monthIndex = 0; ++yearIndex; } monthIndex++; } } if (includeBlankOption.HasValue && includeBlankOption.Value) { dateIndexList.Insert(0, new DateIndex()); } return new JsonResult { Data = new SelectList(dateIndexList, "Code", "Description") }; }
public ActionResult _DateIndexComboBox(string controlName, string controlId, string selectedValue, bool? enable, string dateType, bool? includeBlankOption) { ViewBag.ControlName = controlName; ViewBag.ControlId = controlId; ViewBag.Enable = enable; ViewBag.IncludeBlankOption = includeBlankOption; IList<DateIndex> dateIndexList = new List<DateIndex>(); if (selectedValue != null && selectedValue.Trim() != string.Empty) { DateIndex dateIndex = new DateIndex(); dateIndex.Code = selectedValue; if (dateType == ((int)com.Sconit.CodeMaster.TimeUnit.Week).ToString()) { var dateFrom = Utility.DateTimeHelper.GetWeekIndexDateFrom(selectedValue); //weekOfYear.Description = var str = new StringBuilder(selectedValue); str.Append("("); str.Append(dateFrom.ToString("MM-dd")); str.Append(" -> "); dateFrom = dateFrom.AddDays(6); str.Append(dateFrom.ToString("MM-dd")); str.Append(")"); dateIndex.Description = str.ToString(); } else { dateIndex.Description = selectedValue; } dateIndexList.Add(dateIndex); } return PartialView(new SelectList(dateIndexList, "Code", "Description", selectedValue)); }
public string [] CreateMensaReply(string paramFirst, string paramSecond, MensaBotEntities mensaBotEntities, string channelId, string conversationId, bool forceDate) { bool isShortRequest = false; //check if paramFirst is date, if true -> change order if (!string.IsNullOrEmpty(paramFirst) && string.IsNullOrEmpty(paramSecond)) { var isDate = (MessageInterpreter.Get.FindDate(paramFirst) != DateIndex.none); if (isDate) { paramSecond = paramFirst; paramFirst = null; } } if (string.IsNullOrEmpty(paramFirst)) { paramFirst = DatabaseUtilities.GetValueBytKey(mensaBotEntities, DatabaseUtilities.DefaultMensaTag, channelId, conversationId); if (string.IsNullOrEmpty(paramFirst)) { return new string[] { Lang.please_add + " " + MessageInterpreter.MarkBold(Lang.canteen_name) + "!" } } ; else { isShortRequest = true; } } CanteenName canteenName = MessageInterpreter.Get.FindCanteen(paramFirst); if (canteenName == CanteenName.none) { return(new string[] { Lang.canteen_not_found + ": " + MessageInterpreter.MarkBold(paramFirst) }); } try { if (_canteens == null) { CreateCanteenInfo(); } _canteens[(int)canteenName].LoadElements(3); } catch (Exception e) { return(new string[] { Lang.fail_to_load_information + ": " + MessageInterpreter.MarkBold(paramFirst) }); } DateIndex dateIndex = DateIndex.TODAY; if (!string.IsNullOrEmpty(paramSecond)) { dateIndex = MessageInterpreter.Get.FindDate(paramSecond); if (dateIndex == DateIndex.none) { return(new string[] { Lang.date_not_found + " " + MessageInterpreter.MarkBold(paramSecond) }); } } //Find correct date element. DateTime now = DateTime.Now.ToUniversalTime().AddDays((int)dateIndex).AddHours(1); DayElement[] dayElements = null; try { if (isShortRequest && !forceDate) { int maxDays = 3; for (int i = 0; i < maxDays; i++) { if (i == 0 && now.Hour > 16)//TODO read close time via website { continue; } dayElements = _canteens[(int)canteenName].DayElements.FindAll(t => t.Date.Day == now.AddDays(i).Day).ToArray(); if (dayElements != null && dayElements.Length != 0) { break; } } } else { dayElements = _canteens[(int)canteenName].DayElements.FindAll(t => t.Date.Day == now.Day).ToArray(); } } catch (Exception e) { dayElements = null; } if (dayElements == null || dayElements.Length == 0) { return(new string[] { MessageInterpreter.MarkBold(Lang.could_not_find_date + " " + now.ToString("dd.MM.yyyy") + Lang.broken_heart) }); } IEnumerable <FoodTags> filter = null; try { filter = CommandBucket.Get.GetValue(mensaBotEntities, DatabaseUtilities.IgnoreTags, channelId, conversationId) .Split(MessageInterpreter.ParamDivider) .Select(t => Enum.Parse(typeof(FoodTags), t.ToUpper())) .Cast <FoodTags>(); } catch (Exception e) { filter = null; } string[] menuItems = new string[dayElements.Length]; //List all elements for dayElement for (int i = 0; i < dayElements.Length; i++) { menuItems[i] = Lang.menu_for + ":" + MessageInterpreter.LineBreak + MessageInterpreter.MarkBold(_canteens[(int)canteenName].GetDescription(i)) + " " + Lang.menu_for_at + " " + MessageInterpreter.MarkItalic(dayElements[i].Date.ToString("dd.MM.yyyy")) + MessageInterpreter.DrawLine; foreach (var foodElement in dayElements[i].FoodElements) { bool hideElement = false; var tagResult = ""; if (foodElement.Tags != null) { foreach (var tag in foodElement.Tags) { if (tag != null) { if (filter != null && filter.Contains(tag)) { hideElement = true; break; } tagResult += FoodElement.FoodTagsToEmoji(tag) + ","; } else { tagResult += "❎"; } } } if (tagResult.Length > 1) { tagResult = tagResult.Remove(tagResult.Length - 1, 1).ToLower() + ";"; } string warning = null; if (string.IsNullOrEmpty(foodElement.EnglishName.Trim()) && CultureInfo.CurrentCulture.ToString() != (new CultureInfo("de")).ToString()) { warning = MessageInterpreter.MarkItalic(Lang.no_english_available); } FoodDisplayStyle foodDisplayStyle = FoodDisplayStyle.none; string styleString = GetValue(mensaBotEntities, DatabaseUtilities.StyleTag, channelId, conversationId); if (!string.IsNullOrEmpty(styleString)) { if (!FoodDisplayStyle.TryParse(styleString.ToUpper(), out foodDisplayStyle)) { foodDisplayStyle = FoodDisplayStyle.none; } } var tagsDisplay = ""; switch (foodDisplayStyle) { case FoodDisplayStyle.none: case FoodDisplayStyle.MAXIMUM: tagsDisplay = MessageInterpreter.LineBreak + tagResult + (!string.IsNullOrEmpty(foodElement.Cost) ? foodElement.Cost + "€" : "") + MessageInterpreter.DrawLine; break; case FoodDisplayStyle.MINIMUM_NOLINES: tagsDisplay = MessageInterpreter.LineBreak; break; case FoodDisplayStyle.MINIMUM: tagsDisplay = MessageInterpreter.DrawLine; break; case FoodDisplayStyle.INLINE: tagsDisplay = " " + ((tagResult.Length > 1) ? tagResult.Remove(tagResult.Length - 1, 1) : tagResult) + MessageInterpreter.DrawLine; break; } if (!hideElement) { if (CultureInfo.CurrentCulture.ToString() == (new CultureInfo("de")).ToString() || warning != null) { menuItems[i] += MessageInterpreter.MarkBold(foodElement.GermanName) + warning + " " + tagsDisplay; } else { menuItems[i] += MessageInterpreter.MarkBold(MessageInterpreter.FirstCharToUpper(foodElement.EnglishName)) + " " + tagsDisplay; } } } } return(menuItems); }