मैं वर्तमान में ZedGraph लाइब्रेरी के आधार पर एक प्रवृत्ति समाधान विकसित कर रहा हूं, और मैं डेटाबेस से आने वाली बड़ी मात्रा में डेटा कैश करने के लिए टीफाइल का उपयोग कर रहा हूं।
मुझे नहीं पता कि चायहाउस समाधान के पीछे वास्तव में किस प्रकार की तकनीक खड़ी है। लेकिन मैंने टीफाइल से आने वाली बड़ी मात्रा में डेटा से दो तिथियों के बीच बिंदुओं का एक सेट प्रदर्शित करने के लिए एक दृष्टिकोण का भी उपयोग किया।
ज़ेडग्राफ लाइब्रेरी में FilteredPointList
ऑब्जेक्ट है जो स्वत: डेटा पॉइंट decimation करता है। इसमें SetBounds
विधि शामिल है जो आपको उन तिथियों की श्रेणी चुनने की अनुमति देती है, जिन्हें आप प्रदर्शित करना चाहते हैं, और अधिकतम अंक जो आप दिखाना चाहते हैं। आम तौर पर, यह आपके विचार की वास्तविक चौड़ाई से मेल खाता है।
FilteredPointList
(original source code) डबल के दो सरणी का उपयोग करता है जिसमें XY डेटा होता है। एक टीफाइल ऑब्जेक्ट द्वारा सरणी को प्रतिस्थापित करके TeaFilePointList
पर इस वर्ग को अनुकूलित करना आसान है, टी को उस दिनांक के रूप में देखते हुए जिसमें डेटटाइम और डबल प्रॉपर्टी होती है।
कार्यान्वयन इष्टतम नहीं है, लेकिन मैंने इस तरह से शुरू किया। मैं TeaFile की MemoryMappedFile सुविधा को शामिल करने के लिए बाद में इस कोड को अपडेट कर सकता हूं। यह इस तरह से बहुत तेज होगा।
public class TeaFilePointList : IPointList
{
TeaFile<point> tf;
private int _maxPts = -1;
private int _minBoundIndex = -1;
private int _maxBoundIndex = -1;
struct point
{
public TeaTime.Time x;
public double y;
}
public TeaFilePointList(DateTime[] x, double[] y)
{
tf = TeaFile<point>.Create(Path.GetRandomFileName() + ".tea");
for (var i = 0; i < x.Length; i++)
tf.Write(new point() { x = x[i], y = y[i] });
}
public void SetBounds(double min, double max, int maxPts)
{
_maxPts = maxPts;
// find the index of the start and end of the bounded range
var xmin = (DateTime)new XDate(min);
var xmax = (DateTime)new XDate(max);
int first = tf.BinarySearch(xmin, item => (DateTime)item.x);
int last = tf.BinarySearch(xmax, item => (DateTime)item.x);
// Make sure the bounded indices are legitimate
// if BinarySearch() doesn't find the value, it returns the bitwise
// complement of the index of the 1st element larger than the sought value
if (first < 0)
{
if (first == -1)
first = 0;
else
first = ~(first + 1);
}
if (last < 0)
last = ~last;
_minBoundIndex = first;
_maxBoundIndex = last;
}
public int Count
{
get
{
int arraySize = (int)tf.Count;
// Is the filter active?
if (_minBoundIndex >= 0 && _maxBoundIndex >= 0 && _maxPts > 0)
{
// get the number of points within the filter bounds
int boundSize = _maxBoundIndex - _minBoundIndex + 1;
// limit the point count to the filter bounds
if (boundSize < arraySize)
arraySize = boundSize;
// limit the point count to the declared max points
if (arraySize > _maxPts)
arraySize = _maxPts;
}
return arraySize;
}
}
public PointPair this[int index]
{
get
{
if (_minBoundIndex >= 0 && _maxBoundIndex >= 0 && _maxPts >= 0)
{
// get number of points in bounded range
int nPts = _maxBoundIndex - _minBoundIndex + 1;
if (nPts > _maxPts)
{
// if we're skipping points, then calculate the new index
index = _minBoundIndex + (int)((double)index * (double)nPts/(double)_maxPts);
}
else
{
// otherwise, index is just offset by the start of the bounded range
index += _minBoundIndex;
}
}
double xVal, yVal;
if (index >= 0 && index < tf.Count)
xVal = new XDate(tf.Items[index].x);
else
xVal = PointPair.Missing;
if (index >= 0 && index < tf.Count)
yVal = tf.Items[index].y;
else
yVal = PointPair.Missing;
return new PointPair(xVal, yVal, PointPair.Missing, null);
}
}
public object Clone()
{
throw new NotImplementedException(); // I'm lazy...
}
public void Close()
{
tf.Close();
tf.Dispose();
File.Delete(tf.Name);
}
}
सबसे कठिन हिस्सा एक तिथि समय का उपयोग कर रिकॉर्ड को त्वरित खोजने के लिए बाईफाइल के लिए बाइनरी खोज को कार्यान्वित करना था। मैं एक decompiler का उपयोग करके Array.BinarySearch कार्यान्वयन को देखा है, और मैं नीचे विस्तार लिखा है:
public static int BinarySearch<T, U>(this TeaFile<T> tf, U target, Func<T, U> indexer) where T : struct
{
var lo = 0;
var hi = (int)tf.Count - 1;
var comp = Comparer<U>.Default;
while(lo <= hi)
{
var median = lo + (hi - lo >> 1);
var num = comp.Compare(indexer(tf.Items[median]), target);
if (num == 0)
return median;
if (num < 0)
lo = median + 1;
else
hi = median - 1;
}
return ~lo;
}
ZedGraph अपनी आवश्यकताओं फिट नहीं करता है, तो कम से कम आप विचार आया। FilteredPointList क्लास में उपयोग किया जाने वाला decimation एल्गोरिदम बहुत अच्छा है और आपकी जरूरतों को पूरा करने के लिए अनुकूलित किया जा सकता है।
धन्यवाद लॉरेन, मैं इसी तरह के समाधान के साथ समाप्त हुआ। टीहाउस उत्पाद के हिस्से के रूप में स्रोत कोड का उपलब्ध नहीं था मेरे लिए कोई नहीं था। मैं अपनी खुद की द्विआधारी फ़ाइल संरचना का उपयोग कर समाप्त हुआ और इसे पेशेवर चार्टिंग समाधान (SciChart) को खिलाने के लिए अनुकूलित किया। इस तरह से मैं अधिकांश स्रोत कोड के नियंत्रण में हूं। –