Implement Laboratory and TimePoints.
This commit is contained in:
@ -108,7 +108,7 @@ namespace zaaReloaded2.Importer.ZaaImporter
|
||||
foreach (Capture itemCapture in m.Groups["items"].Captures)
|
||||
{
|
||||
LaurisItem i = new LaurisItem(itemCapture.Value, _parameterDictionary, _unitDictionary);
|
||||
Items.Add(i.QualifiedName, i);
|
||||
Items[i.QualifiedName] = i;
|
||||
}
|
||||
IsLaurisParagraph = Items.Count > 0;
|
||||
}
|
||||
|
@ -32,12 +32,52 @@ namespace zaaReloaded2.Importer.ZaaImporter
|
||||
/// </summary>
|
||||
class LaurisTimePoint : TimePoint
|
||||
{
|
||||
#region Static methods
|
||||
|
||||
/// <summary>
|
||||
/// Examines a string and returns true if it resembles
|
||||
/// a time stamp line in the Lauris output.
|
||||
/// </summary>
|
||||
/// <param name="line">Line to examine.</param>
|
||||
/// <returns>True if line resembles a time stamp line
|
||||
/// in the Lauris output.</returns>
|
||||
static public bool IsTimeStampLine(string line)
|
||||
{
|
||||
return _timeStampRegex.IsMatch(line);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a Regex object that matches a Lauris time stamp
|
||||
/// line.
|
||||
/// </summary>
|
||||
static public Regex TimeStampRegex
|
||||
{
|
||||
get
|
||||
{
|
||||
return _timeStampRegex;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets an array of paragraphs in this LaurisText.
|
||||
/// </summary>
|
||||
public string[] Paragraphs { get; private set; }
|
||||
public string[] Paragraphs
|
||||
{
|
||||
[DebuggerStepThrough]
|
||||
get
|
||||
{
|
||||
return _paragraphs;
|
||||
}
|
||||
set
|
||||
{
|
||||
_paragraphs = value;
|
||||
ParseParagraphs();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is true if the LaurisText has time stamp in the first
|
||||
@ -62,7 +102,6 @@ namespace zaaReloaded2.Importer.ZaaImporter
|
||||
Paragraphs = value.Split(
|
||||
new string[] { Environment.NewLine },
|
||||
StringSplitOptions.None);
|
||||
ParseParagraphs();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -73,23 +112,35 @@ namespace zaaReloaded2.Importer.ZaaImporter
|
||||
|
||||
public LaurisTimePoint() { }
|
||||
|
||||
public LaurisTimePoint(string laurisTest)
|
||||
: this()
|
||||
{
|
||||
_parameterDictionary = null;
|
||||
_unitDictionary = null;
|
||||
LaurisText = laurisTest;
|
||||
}
|
||||
|
||||
public LaurisTimePoint(
|
||||
string laurisTest,
|
||||
string laurisText,
|
||||
ParameterDictionary parameterDictionary,
|
||||
UnitDictionary unitDictionary)
|
||||
: this()
|
||||
{
|
||||
_parameterDictionary = parameterDictionary;
|
||||
_unitDictionary = unitDictionary;
|
||||
LaurisText = laurisTest;
|
||||
LaurisText = laurisText;
|
||||
}
|
||||
|
||||
public LaurisTimePoint(string laurisText)
|
||||
: this(laurisText, null, null)
|
||||
{ }
|
||||
|
||||
public LaurisTimePoint(
|
||||
string[] paragraphs,
|
||||
ParameterDictionary parameterDictionary,
|
||||
UnitDictionary unitDictionary)
|
||||
: this()
|
||||
{
|
||||
_parameterDictionary = parameterDictionary;
|
||||
_unitDictionary = unitDictionary;
|
||||
Paragraphs = paragraphs;
|
||||
}
|
||||
|
||||
public LaurisTimePoint(string[] paragraphs)
|
||||
: this(paragraphs, null, null)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -139,7 +190,7 @@ namespace zaaReloaded2.Importer.ZaaImporter
|
||||
if (Paragraphs.Length == 0)
|
||||
throw new InvalidOperationException("The time point has no paragraphs.");
|
||||
|
||||
Match m = _dateStampRegex.Match(Paragraphs[0]);
|
||||
Match m = _timeStampRegex.Match(Paragraphs[0]);
|
||||
bool success = false;
|
||||
if (m.Success)
|
||||
{
|
||||
@ -158,7 +209,7 @@ namespace zaaReloaded2.Importer.ZaaImporter
|
||||
|
||||
void AddItems(IItemDictionary items)
|
||||
{
|
||||
|
||||
Items.Merge(items);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -169,8 +220,9 @@ namespace zaaReloaded2.Importer.ZaaImporter
|
||||
/// A regular expression that matches the time stamp in the first
|
||||
/// paragraph of a LaurisText.
|
||||
/// </summary>
|
||||
static readonly Regex _dateStampRegex = new Regex(
|
||||
@"^\s*\[?\s*(?<datetime>\d\d\.\d\d\.\d\d\d\d\s+\d\d:\d\d)");
|
||||
static readonly Regex _timeStampRegex = new Regex(
|
||||
@"^\s*\(?\s*(?<datetime>\d\d\.\d\d\.\d\d\d\d\s+\d\d:\d\d)");
|
||||
string[] _paragraphs;
|
||||
ParameterDictionary _parameterDictionary;
|
||||
UnitDictionary _unitDictionary;
|
||||
|
||||
|
@ -20,6 +20,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Bovender.Extensions;
|
||||
using zaaReloaded2.LabModel;
|
||||
|
||||
namespace zaaReloaded2.Importer.ZaaImporter
|
||||
@ -34,21 +35,68 @@ namespace zaaReloaded2.Importer.ZaaImporter
|
||||
|
||||
public Laboratory Laboratory
|
||||
{
|
||||
[DebuggerStepThrough]
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (_laboratory == null)
|
||||
{
|
||||
_laboratory = new Laboratory();
|
||||
}
|
||||
return _laboratory;
|
||||
}
|
||||
[DebuggerStepThrough]
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
_laboratory = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void Import(string text)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
string[] paragraphs = text.Split(
|
||||
new string[] { Environment.NewLine },
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
int i = 0;
|
||||
int start = 0;
|
||||
int numParagraphs = paragraphs.Length;
|
||||
|
||||
while (i < numParagraphs)
|
||||
{
|
||||
// Search for the next occurrence of a time stamp line
|
||||
while (i < numParagraphs
|
||||
&& !LaurisTimePoint.IsTimeStampLine(paragraphs[i]))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
// TODO: Find an alternative to returning in the middle of the method.
|
||||
if (i >= numParagraphs) return;
|
||||
|
||||
if (LaurisTimePoint.IsTimeStampLine(paragraphs[i]))
|
||||
{
|
||||
// Remember the time stamp line's index
|
||||
start = i;
|
||||
|
||||
// Seek the next time stamp line
|
||||
while (i + 1 < numParagraphs
|
||||
&& !LaurisTimePoint.IsTimeStampLine(paragraphs[i + 1]))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
Laboratory.AddTimePoint(
|
||||
new LaurisTimePoint(paragraphs.Slice(start, i - start + 1))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
|
||||
Laboratory _laboratory;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -32,5 +32,40 @@ namespace zaaReloaded2.LabModel
|
||||
public SortedDictionary<DateTime, TimePoint> TimePoints { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
public Laboratory()
|
||||
{
|
||||
TimePoints = new SortedDictionary<DateTime, TimePoint>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new time point with laboratory items to the laboratory.
|
||||
/// If a time point with same time stamp exists already, the new
|
||||
/// items will be added to the existing ones.
|
||||
/// </summary>
|
||||
/// <param name="timePoint">Time point to add to the laboratory.</param>
|
||||
public void AddTimePoint(TimePoint timePoint)
|
||||
{
|
||||
if (timePoint == null)
|
||||
throw new ArgumentNullException("timePoint");
|
||||
|
||||
TimePoint tp;
|
||||
if (TimePoints.TryGetValue(timePoint.TimeStamp, out tp))
|
||||
{
|
||||
tp.MergeItems(timePoint);
|
||||
}
|
||||
else
|
||||
{
|
||||
TimePoints[timePoint.TimeStamp] = timePoint;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -48,5 +48,25 @@ namespace zaaReloaded2.LabModel
|
||||
public IItemDictionary Items { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Adds the items from another time point to this
|
||||
/// time point. There is no check for plausibility,
|
||||
/// i.e. the other time point may have a different
|
||||
/// time stamp.
|
||||
/// </summary>
|
||||
/// <param name="otherTimePoint">Other TimePoint to
|
||||
/// merge into the current one.</param>
|
||||
public void MergeItems(TimePoint otherTimePoint)
|
||||
{
|
||||
if (otherTimePoint == null)
|
||||
throw new ArgumentNullException("otherTimePoint");
|
||||
|
||||
Items.Merge(otherTimePoint.Items);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
packages.config
|
||||
part of zaaReloaded2
|
||||
|
||||
Copyright 2015 Daniel Kraus
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<packages>
|
||||
<package id="Bovender" version="0.1.0.0" targetFramework="net40" />
|
||||
<package id="Bovender" version="0.2.0.0" targetFramework="net40" />
|
||||
<package id="Expression.Blend.Sdk" version="1.0.2" targetFramework="net40" />
|
||||
</packages>
|
@ -111,6 +111,9 @@
|
||||
-->
|
||||
<ItemGroup>
|
||||
<Reference Include="Accessibility" />
|
||||
<Reference Include="Bovender">
|
||||
<HintPath>..\packages\Bovender.0.2.0.0\lib\net40\Bovender.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
@ -187,6 +190,7 @@
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<None Include="packages.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
|
Reference in New Issue
Block a user