Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9041 for branches


Ignore:
Timestamp:
12/12/12 16:50:46 (12 years ago)
Author:
abeham
Message:

#1985:

  • Moved code to format and parse timespans to a TimeSpanHelper class
  • Added a dialog for defining arithmetic sequences of timespans
Location:
branches/RuntimeOptimizer
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/RuntimeOptimizer/HeuristicLab.Common/3.3/HeuristicLab.Common-3.3.csproj

    r8600 r9041  
    135135    <Compile Include="Plugin.cs" />
    136136    <Compile Include="ReferenceEqualityComparer.cs" />
     137    <Compile Include="TimeSpanHelper.cs" />
    137138    <Compile Include="TypeEqualityComparer.cs" />
    138139    <Compile Include="TypeExtensions.cs" />
     
    180181  -->
    181182  <PropertyGroup>
    182    <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
     183    <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
    183184set ProjectDir=$(ProjectDir)
    184185set SolutionDir=$(SolutionDir)
     
    187188call PreBuildEvent.cmd
    188189</PreBuildEvent>
    189 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">
     190    <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">
    190191export ProjectDir=$(ProjectDir)
    191192export SolutionDir=$(SolutionDir)
  • branches/RuntimeOptimizer/HeuristicLab.MainForm.WindowsForms/3.3/HeuristicLab.MainForm.WindowsForms-3.3.csproj

    r8975 r9041  
    126126      <DependentUpon>DragOverTabControl.cs</DependentUpon>
    127127    </Compile>
     128    <Compile Include="Dialogs\DefineArithmeticProgressionTimeDialog.cs">
     129      <SubType>Form</SubType>
     130    </Compile>
     131    <Compile Include="Dialogs\DefineArithmeticProgressionTimeDialog.Designer.cs">
     132      <DependentUpon>DefineArithmeticProgressionTimeDialog.cs</DependentUpon>
     133    </Compile>
    128134    <Compile Include="Dialogs\DefineArithmeticProgressionDialog.cs">
    129135      <SubType>Form</SubType>
  • branches/RuntimeOptimizer/HeuristicLab.Optimization.Views/3.3/TimeLimitRunView.Designer.cs

    r9040 r9041  
    202202      // openAlgorithmButton
    203203      //
    204       this.openAlgorithmButton.Image = ((System.Drawing.Image)(resources.GetObject("openAlgorithmButton.Image")));
     204      this.openAlgorithmButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Open;
    205205      this.openAlgorithmButton.Location = new System.Drawing.Point(36, 6);
    206206      this.openAlgorithmButton.Name = "openAlgorithmButton";
     
    213213      // newAlgorithmButton
    214214      //
    215       this.newAlgorithmButton.Image = ((System.Drawing.Image)(resources.GetObject("newAlgorithmButton.Image")));
     215      this.newAlgorithmButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.NewDocument;
    216216      this.newAlgorithmButton.Location = new System.Drawing.Point(6, 6);
    217217      this.newAlgorithmButton.Name = "newAlgorithmButton";
  • branches/RuntimeOptimizer/HeuristicLab.Optimization.Views/3.3/TimeLimitRunView.cs

    r9040 r9041  
    8484      try {
    8585        if (Content == null) {
    86           timeLimitTextBox.Text = FormatTimeSpan(TimeSpan.FromSeconds(60));
     86          timeLimitTextBox.Text = TimeSpanHelper.FormatNatural(TimeSpan.FromSeconds(60));
    8787          snapshotsTextBox.Text = String.Empty;
    8888          storeAlgorithmInEachSnapshotCheckBox.Checked = false;
     
    9191          runsView.Content = null;
    9292        } else {
    93           timeLimitTextBox.Text = FormatTimeSpan(Content.MaximumExecutionTime);
    94           snapshotsTextBox.Text = String.Join(" ; ", Content.SnapshotTimes.Select(x => FormatTimeSpan(x, true)));
     93          timeLimitTextBox.Text = TimeSpanHelper.FormatNatural(Content.MaximumExecutionTime);
     94          snapshotsTextBox.Text = String.Join(" ; ", Content.SnapshotTimes.Select(x => TimeSpanHelper.FormatNatural(x, true)));
    9595          storeAlgorithmInEachSnapshotCheckBox.Checked = Content.StoreAlgorithmInEachSnapshot;
    9696          algorithmViewHost.Content = Content.Algorithm;
     
    137137          SuppressEvents = true;
    138138          try {
    139             timeLimitTextBox.Text = FormatTimeSpan(Content.MaximumExecutionTime);
     139            timeLimitTextBox.Text = TimeSpanHelper.FormatNatural(Content.MaximumExecutionTime);
    140140          } finally { SuppressEvents = false; }
    141141          break;
     
    144144          try {
    145145            if (Content.SnapshotTimes.Any())
    146               snapshotsTextBox.Text = String.Join(" ; ", Content.SnapshotTimes.Select(x => FormatTimeSpan(x, true)));
     146              snapshotsTextBox.Text = String.Join(" ; ", Content.SnapshotTimes.Select(x => TimeSpanHelper.FormatNatural(x, true)));
    147147            else snapshotsTextBox.Text = String.Empty;
    148148            Content.SnapshotTimes.ItemsAdded += Content_SnapshotTimes_Changed;
     
    184184      try {
    185185        if (Content.SnapshotTimes.Any())
    186           snapshotsTextBox.Text = string.Join(" ; ", Content.SnapshotTimes.Select(x => FormatTimeSpan(x, true)));
     186          snapshotsTextBox.Text = string.Join(" ; ", Content.SnapshotTimes.Select(x => TimeSpanHelper.FormatNatural(x, true)));
    187187        else snapshotsTextBox.Text = String.Empty;
    188188      } finally { SuppressEvents = false; }
     
    194194      if (SuppressEvents) return;
    195195      TimeSpan ts;
    196       if (!TryGetTimeSpanFromFormat(timeLimitTextBox.Text, out ts)) {
     196      if (!TimeSpanHelper.TryGetFromNaturalFormat(timeLimitTextBox.Text, out ts)) {
    197197        e.Cancel = true;
    198198        errorProvider.SetError(timeLimitTextBox, "Please enter a valid time span, e.g. 60, 20s, 45 seconds, 3h, 1 hour, 4 d, 2 days");
     
    200200        Content.MaximumExecutionTime = ts;
    201201        e.Cancel = false;
    202         errorProvider.SetError(timeLimitTextBox, String.Empty);
     202        errorProvider.SetError(timeLimitTextBox, null);
    203203      }
    204204    }
     
    207207      if (SuppressEvents) return;
    208208      e.Cancel = false;
    209       errorProvider.SetError(timeLimitTextBox, String.Empty);
     209      errorProvider.SetError(snapshotsTextBox, null);
    210210
    211211      var snapshotTimes = new ObservableList<TimeSpan>();
     
    213213      foreach (Match m in matches) {
    214214        TimeSpan value;
    215         if (!TryGetTimeSpanFromFormat(m.Value, out value)) {
     215        if (!TimeSpanHelper.TryGetFromNaturalFormat(m.Value, out value)) {
    216216          e.Cancel = !snapshotsTextBox.ReadOnly && snapshotsTextBox.Enabled; // don't cancel an operation that cannot be edited
    217217          errorProvider.SetError(snapshotsTextBox, "Error parsing " + m.Value + ", please provide a valid time span, e.g. 60, 20s, 45 seconds, 3h, 1 hour, 4 d, 2 days");
     
    297297
    298298    private void sequenceButton_Click(object sender, EventArgs e) {
    299       using (var dialog = new DefineArithmeticProgressionDialog(false, 1, Content.MaximumExecutionTime.TotalSeconds, 1)) {
     299      using (var dialog = new DefineArithmeticTimeSpanProgressionDialog(TimeSpan.FromSeconds(1), Content.MaximumExecutionTime, TimeSpan.FromSeconds(1))) {
    300300        if (dialog.ShowDialog() == DialogResult.OK) {
    301301          if (dialog.Values.Any())
    302             Content.SnapshotTimes = new ObservableList<TimeSpan>(dialog.Values.Select(TimeSpan.FromSeconds));
     302            Content.SnapshotTimes = new ObservableList<TimeSpan>(dialog.Values);
    303303          else Content.SnapshotTimes = new ObservableList<TimeSpan>();
    304304        }
     
    307307    #endregion
    308308    #endregion
    309 
    310     private string FormatTimeSpan(TimeSpan ts, bool abbrevUnit = false) {
    311       if (ts.TotalSeconds < 180) return ts.TotalSeconds + (abbrevUnit ? "s" : " seconds");
    312       if (ts.TotalMinutes < 180) return ts.TotalMinutes + (abbrevUnit ? "min" : " minutes");
    313       if (ts.TotalHours < 96) return ts.TotalHours + (abbrevUnit ? "h" : " hours");
    314       return ts.TotalDays + (abbrevUnit ? "d" : " days");
    315     }
    316 
    317     private bool TryGetTimeSpanFromFormat(string text, out TimeSpan result) {
    318       double value;
    319       result = TimeSpan.Zero;
    320 
    321       var numberMatch = Regex.Match(text, @"\d+");
    322       if (!numberMatch.Success) return false;
    323 
    324       if (!double.TryParse(numberMatch.Value, out value))
    325         return false;
    326 
    327       var unitMatch = Regex.Match(text, @"[a-zA-Z]+$");
    328       if (!unitMatch.Success) return false;
    329 
    330       switch (unitMatch.Value) {
    331         case "d":
    332         case "day":
    333         case "days": result = TimeSpan.FromDays(value); break;
    334         case "h":
    335         case "hour":
    336         case "hours": result = TimeSpan.FromHours(value); break;
    337         case "min":
    338         case "minute":
    339         case "minutes": result = TimeSpan.FromMinutes(value); break;
    340         case "s":
    341         case "second":
    342         case "seconds": result = TimeSpan.FromSeconds(value); break;
    343         default: return false;
    344       }
    345       return true;
    346     }
    347309  }
    348310}
Note: See TracChangeset for help on using the changeset viewer.