I’m already suing DateTime.Now. The code below returns me a string in the format I want, look below:
public string GetTime() {
string horaFormat = "";
string minFormat = "";
string segundoFormat = "";
string diaFormat = "";
string mesFormat = "";
dataAtual = DateTime.Now;
varHora = dataAtual.Hour;
varMinuto = dataAtual.Minute;
varSegundo = dataAtual.Second;
varDia = dataAtual.Day;
varMes = dataAtual.Month;
varAno = dataAtual.Year;
if (varDia >= 0.0f varDia <= 9.0f){
diaFormat = "0" + varDia.ToString();
} else {
diaFormat = varDia.ToString();
}
if (varMes >= 0.0f varMes <= 9.0f){
mesFormat = "0" + varMes.ToString();
} else {
mesFormat = varMes.ToString();
}
if (varHora >= 0.0f varHora <= 9.0f){
horaFormat = "0" + varHora.ToString();
} else {
horaFormat = varHora.ToString();
}
if (varMinuto >= 0.0f varMinuto <= 9.0f){
minFormat = "0" + varMinuto.ToString();
} else {
minFormat = varMinuto.ToString();
}
if (varSegundo >= 0.0f varSegundo <= 9.0f){
segundoFormat = "0" + varSegundo.ToString();
} else {
segundoFormat = varSegundo.ToString();
}
currentTime = varAno + "" + mesFormat + "" + diaFormat + "" + horaFormat + "" + minFormat + "" + segundoFormat;
currentTimeBD = varAno + "-" + mesFormat + "-" + diaFormat + " " + horaFormat + ":" + minFormat + ":" + segundoFormat;
diaResposta = diaFormat + "-" + mesFormat + "-" + varAno;
return currentTime;
}
In variable currentTime I store the date I need. Then I only select the datas based on the current time/second I want.
I’m already filtering everything based on time and the iPods IDs I want.
The code below save the first data into table A.
public void SaveDatas(string id_aparelho, string horario, string valor, string useMedia, string local) {
string sqlQuery = "INSERT INTO registros (id, id_aparelho, horario, valor, usaMedia, local) VALUES ('0', '"
+ id_aparelho + "', '" + horario + "', '" + valor + "', '" + useMedia + "', '" + local + "')";
IDbCommand dbCommand = conexaoDB.CreateCommand();
dbCommand.CommandText = sqlQuery;
IDataReader reader = dbCommand.ExecuteReader();
reader.Close();
reader = null;
dbCommand.Dispose();
dbCommand = null;
}
And the code below calculates one of the average value.
public void SaveAveragePotValue (){
string sqlQuery = "SELECT AVG(valor) As ValorMedio FROM registros WHERE usaMedia = 'True' GROUP BY horario";
float avValue = 0.0f;
IDbCommand dbCommand1 = MySQL.Instance.conexaoDB.CreateCommand();
dbCommand1.CommandText = sqlQuery;
IDataReader sqlReader1 = dbCommand1.ExecuteReader();
while (sqlReader1.Read()) {
//ver valor medio
averagevalue = "0";
//Debug.Log(sqlReader1["ValorMedio"]);
averagevalue = (sqlReader1["ValorMedio"]).ToString();
//avValue = (float)Convert.ToDouble(averagevalue);
avValue = float.Parse(averagevalue);
avValue = Mathf.Round(avValue * 1000);
avValue = avValue/1000;
//Debug.Log("Valor medio alterado: " + avValue);
averagevalue = avValue.ToString();
averagevalue = averagevalue.Replace(",", ".");
}
sqlReader1.Close();
sqlReader1 = null;
dbCommand1.Dispose();
dbCommand1 = null;
//CALCULA DESVIO PADRAO ****************************
sqlQuery = "SELECT * FROM registros WHERE usaMedia = 'True' AND horario = '" + currentTimeBD + "'";
IDbCommand dbCommand3 = MySQL.Instance.conexaoDB.CreateCommand();
dbCommand3.CommandText = sqlQuery;
IDataReader sqlReader3 = dbCommand3.ExecuteReader();
float[] qtdeCalculos = new float[QView.Instance.arrClients.Count];
int cont = 0;
float mediaValores = 0f;
float somaDP = 0f;
while (sqlReader3.Read()) {
qtdeCalculos[cont] = float.Parse((sqlReader3["valor"]).ToString());
mediaValores += qtdeCalculos[cont];
//Debug.Log(cont + ": " + qtdeCalculos[cont]);
cont++;
}
//Debug.Log("Media: " + mediaValores);
mediaValores = mediaValores / QView.Instance.arrClients.Count;
cont = 0;
while (cont < QView.Instance.arrClients.Count){
qtdeCalculos[cont] = Mathf.Pow((qtdeCalculos[cont] - mediaValores),2);
//Debug.Log("Novo " + cont + ": " + qtdeCalculos[cont]);
cont++;
}
cont = 0;
while (cont < QView.Instance.arrClients.Count){
somaDP += qtdeCalculos[cont];
cont++;
}
somaDP = somaDP / cont;
desvioPadrao = (Mathf.Sqrt(somaDP)).ToString();
//Debug.Log("somaDP: " + somaDP);
//Debug.Log("desvioPadrao: " + desvioPadrao);
float arredonda = float.Parse(desvioPadrao);
arredonda = Mathf.Round(arredonda * 1000);
arredonda = arredonda/1000;
desvioPadrao = arredonda.ToString();
desvioPadrao = desvioPadrao.Replace(",", ".");
//Debug.Log("arredonda: " + desvioPadrao);
sqlReader3.Close();
sqlReader3 = null;
dbCommand3.Dispose();
dbCommand3 = null;
//SALVAR DADOS
sqlQuery = "INSERT INTO evento (tipo, dh_evento, valor, dp, qtde_p, valor1, valor2, valor3, valor4, valor5, valor6, valor7, valor8, valor9, valor10) VALUES ('"
+ nomeCampoMedia + "', '" + currentTime + "', '" + averagevalue + "', '" + desvioPadrao + "', '" + (QView.Instance.arrClients.Count).ToString()
+ "', '0' " + ", '0' " + ", '0' " + ", '0' " + ", '0' " + ", '0' " + ", '0' " + ", '0' " + ", '0' " + ", '0')";
IDbCommand dbCommand2 = MySQL.Instance.conexaoDB.CreateCommand();
dbCommand2.CommandText = sqlQuery;
IDataReader sqlReader2 = dbCommand2.ExecuteReader();
sqlReader2.Close();
sqlReader2 = null;
dbCommand2.Dispose();
dbCommand2 = null;
desvioPadrao = "0";
}
The code above can be a little confusing for your, because I’m not giving you all the variables necessary to understand, but what I want to show you how I’m doing it. If you want, I can explain better to you by MSN or GMAIL, or anyother live chat 
EDIT: I just made a test… I’m runnin the server inside a Core i7 with 8 GB memory… funny is that the server is not eating memory… in fact, is very stable… but If I throw it to a XP PC, it starts to increase memory every second… maybe that’s why it crashs. But I don’t think my server needs just a Core i7 with 8 GB of Ram…
EDIT 2: sometimes it crashs, and sometimes not… WTF :lol: