public TimeValueData getData(long timestamp, string dataName, string instrument) { SQLiteConnection connection = getConnection(); SQLiteCommand command = new SQLiteCommand("SELECT * FROM timevaluepair WHERE instrument = @instrument AND name = @name AND timestamp < @timestamp AND timestamp > @timestampMin ORDER BY timestamp DESC LIMIT 1", connection); command.Parameters.AddWithValue("@timestamp", timestamp); command.Parameters.AddWithValue("@name", dataName); command.Parameters.AddWithValue("@instrument", instrument); command.Parameters.AddWithValue("@timestampMin", timestamp - (30 * 60 * 1000)); command.Prepare(); command.CommandTimeout = timeout; SQLiteDataReader Reader = command.ExecuteReader(); TimeValueData output = null; if (Reader.Read()) { output = new TimeValueData((long)(decimal)Reader["timestamp"], (double)Reader["value"]); } Reader.Close(); connection.Close(); return(output); }
public void setData(TimeValueData data, string dataName, string instrument) { try { BsonDocument input = new BsonDocument(); input.SetElement(new BsonElement("timestamp", data.timestamp)); input.SetElement(new BsonElement("value", data.value)); input.SetElement(new BsonElement("dataName", dataName)); dataCollection.Insert(input); } catch { errors++; } }
public void setData(TimeValueData data, string dataName, string instrument) { SQLiteConnection connection = getConnection(); SQLiteCommand command = new SQLiteCommand("INSERT INTO timevaluepair(instrument, name, timestamp, value) VALUES(@instrument, @dataName, @timestamp, @value)", connection); command.Parameters.AddWithValue("@value", format(data.value)); command.Parameters.AddWithValue("@timestamp", data.timestamp); command.Parameters.AddWithValue("@dataName", dataName); command.Parameters.AddWithValue("@instrument", instrument); command.Prepare(); command.CommandTimeout = timeout; command.ExecuteNonQuery(); connection.Close(); }
void IDataminingDatabase.addData(string dataname, SQLiteDatabase database, string instrument) { List <Thread> threads = new List <Thread>(); long start = database.getFirstTimestamp(); long end = database.getLastTimestamp(); long timeframe = (end - start) / threadsCount; int threadId = 0; var collection = mongodb.getDB().GetCollection("prices"); while (threadId < threadsCount) { long threadBeginning = start + (timeframe * threadId); long threadEnd = threadBeginning + timeframe; Thread thread = new Thread(delegate() { string name = "data " + dataname + " ID_" + threadBeginning + ":" + threadEnd; progress.setProgress(name, 0); int done = 0; long count = 0; var docs = collection.FindAs <BsonDocument>(Query.And(Query.EQ("instrument", instrument), Query.NotExists(dataname), Query.LT("timestamp", threadEnd), Query.GTE("timestamp", threadBeginning))).SetSortOrder(SortBy.Ascending("timestamp")); docs.SetFlags(QueryFlags.NoCursorTimeout); count = docs.Count(); foreach (BsonDocument doc in docs) { done++; progress.setProgress(name, Convert.ToInt32(Convert.ToDouble(done) / Convert.ToDouble(count) * 100d)); if (doc.ContainsValue(dataname)) { continue; } try { TimeValueData data = database.getData(doc["timestamp"].AsInt64, dataname, doc["instrument"].AsString); collection.FindAndModify(new FindAndModifyArgs() { Query = Query.EQ("_id", doc["_id"]), Update = Update.Set(dataname, data.value) }); } catch { } } progress.remove(name); }); thread.Start(); threads.Add(thread); threadId++; } waitForThreads(threads); }