Italian [risolto] B4J - DATI CHE VANNO AL DIAVOLO

ivanomonti

Expert
Licensed User
Longtime User
CIAO RAGAZZI :cool::eek::p, ho un piccolo problema che mi fa diventare femmina che sclera, scenario faccio un cavolo di intervallo e ritorno al quesito di ieri delle date e qui va tutto ok, a questo punto ci metto le query per fare la conta degli appuntamenti e chissà perché al primo click mi da dei valori ma al successivi click i valori sballano ma le query sono giuste in questo caso parto dal 29-03-2020 al 04-05-2020.

1) le date vanno liscie e perfette ad ogni click
2) il risultato varia
3) gli appuntamenti sono sempre gli stessi

ACCETTO CRITICHE COSTRUTTIVE MA PREFERISCO CONSIGLI PER OTTIMIZZARE IL TUTTO

2020-04-30_222208.jpg


y = valore massimo degli appuntamenti
x = numero del giorno

classe utilizzata e xchart per i grafici ( @klaus ) che ad ogni click parto da zero azzerando i valori precedenti, quindi dovrebbe ridarmi la stessa visualizzazione dei dati invece sembra vada a cazzo.
( i Nomi delle variabili sono alla cxxxo perchè prima di montare il tutto nell'app voglio testare bene il cdice)

@dragonblu19 qui puoi prendere degli spunti :)

B4X:
#Region Project Attributes
    #MainFormWidth: 800
    #MainFormHeight: 800
    #AdditionalJar: sqlite-jdbc-3.7.2
#End Region

Sub Process_Globals
  
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
  
    Private BarChart1 As xChart
    Private BarChart2 As xChart
    Private BarChart3 As xChart
    Private BarChart4 As xChart
    Private BarChart5 As xChart
    Private BarChart6 As xChart
  
    Private xChart1 As xChart
    Private xChart2 As xChart
  
    Private Button1 As Button
    Private Button2 As Button
    Private Button3 As Button
  
    Private DatePicker1 As DatePicker
  
    Public usernamelogin As String = Null
    Public  passwordlogin As String = Null
    Public idlogin As String = "20200425171020"
    Public phonelogin As String = Null
    Public maillogin As String = Null
  
End Sub

Sub AppStart (Form1 As Form, Args() As String)
  
    MainForm = Form1
    MainForm.RootPane.LoadLayout("ChartLayout")
    MainForm.Stylesheets.Add(File.GetUri(File.DirAssets,"css-33.css"))
    MainForm.Show
  
    DatePicker1.DateFormat="yyyy-MM-dd"
    DateTime.DateFormat="yyyy-MM-dd"
  
End Sub

Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub count_Item_Calendar_For_Month

    Dim year, month, day, week, endmonth As Long
    DateTime.DateFormat="yyyy-MM-dd"
  
    Dim oggi As String = DateTime.Date(DatePicker1.DateTicks)
    Dim iniziosettimanadelmese, giornoinprocessione, testday As String
  
    year = DateTime.GetYear(DateTime.DateParse(oggi))
    month = DateTime.GetMonth(DateTime.DateParse(oggi))
    day = 1
    week = DateTime.GetDayOfWeek(DateTime.DateParse(oggi))
  
    Select month
        Case 1
            Log("gennaio")
            endmonth=31
        Case 2
            Log("febbraio")
            endmonth=28
        Case 3
            Log("marzo")
            endmonth=31
        Case 4
            Log("aprile")
            endmonth=30
        Case 5
            Log("maggio")
            endmonth=31
        Case 6
            Log("giugno")
            endmonth=30
        Case 7
            Log("luglio")
            endmonth=31
        Case 8
            Log("agosto")
            endmonth=31
        Case 9
            Log("settembre")
            endmonth=30
        Case 10
            Log("ottobre")
            endmonth=31
        Case 11
            Log("novembre")
            endmonth=30
        Case 12
            Log("dicembre")
            endmonth=31
    End Select

    Select week
        Case 1
            Log("domenica")
            week=6
        Case 2
            Log("lunedì")
            week=0
        Case 3
            Log("martedì")
            week=1
        Case 4
            Log("mercoledì")
            week=2
        Case 5
            Log("giovedì")
            week=3
        Case 6
            Log("venerdì")
            week=4
        Case 7
            Log("sabato")
            week=5
    End Select
  
    iniziosettimanadelmese = DateTime.Date( DateTime.DateParse(oggi)-(DateTime.TicksPerDay*(week)))
    giornoinprocessione= iniziosettimanadelmese
  
    Dim mm, dd As String

    If File.Exists(File.DirApp,"lavagna.sqlite")  = False Then Return
  
    Dim sqlite As SQL
    sqlite.InitializeSQLite(File.DirApp,"lavagna.sqlite", False)

    If CreateBarData(xChart1) = True Then
    End If
  
    For i = 1 To endmonth

        If month < 10 Then
            mm="0"& month
        Else
            mm = month
        End If
      
        If i < 10 Then
            dd = "0"&i
        Else
            dd = i
        End If
      
        Dim query As String ="select count(*) from calendars where userid='" & idlogin & "' and dateapp='" & year &"-"& mm & "-" & dd  & "' ORDER BY dateapp;"
  
        sqliteexecuty(sqlite,query,xChart1,dd)

    Next
  
End Sub

Sub count_Item_Calendar_for_week

    Dim year, month, day, week, endmonth As Long
    DateTime.DateFormat="yyyy-MM-dd"
  
    Dim oggi As String = "2020-04-01"
    Dim iniziosettimanadelmese, giornoinprocessione, testday As String
  
    year = DateTime.GetYear(DateTime.DateParse(oggi))
    month = DateTime.GetMonth(DateTime.DateParse(oggi))
    day = 1
    week = DateTime.GetDayOfWeek(DateTime.DateParse(oggi))
  
    Select month
        Case 1
            Log("gennaio")
            endmonth=31
        Case 2
            Log("febbraio")
            endmonth=28
        Case 3
            Log("marzo")
            endmonth=31
        Case 4
            Log("aprile")
            endmonth=30
        Case 5
            Log("maggio")
            endmonth=31
        Case 6
            Log("giugno")
            endmonth=30
        Case 7
            Log("luglio")
            endmonth=31
        Case 8
            Log("agosto")
            endmonth=31
        Case 9
            Log("settembre")
            endmonth=30
        Case 10
            Log("ottobre")
            endmonth=31
        Case 11
            Log("novembre")
            endmonth=30
        Case 12
            Log("dicembre")
            endmonth=31
    End Select

    Select week
        Case 1
            Log("domenica")
            week=6
        Case 2
            Log("lunedì")
            week=0
        Case 3
            Log("martedì")
            week=1
        Case 4
            Log("mercoledì")
            week=2
        Case 5
            Log("giovedì")
            week=3
        Case 6
            Log("venerdì")
            week=4
        Case 7
            Log("sabato")
            week=5
    End Select
  
    iniziosettimanadelmese = DateTime.Date( DateTime.DateParse(oggi)-(DateTime.TicksPerDay*(week)))
    giornoinprocessione= iniziosettimanadelmese
  
    Dim mm, dd As String

    If File.Exists(File.DirApp,"lavagna.sqlite")  = False Then Return
    Dim sqlite As SQL
    sqlite.InitializeSQLite(File.DirApp,"lavagna.sqlite", False)
  
  
    For ss=1 To 5
        For i=1 To 7
            #region da rivedere
    '            If ss>=5 Then
    '                testday = DateTime.Date( DateTime.DateParse(iniziosettimanadelmese)+(DateTime.TicksPerDay*(i)))
    '                If DateTime.GetMonth(DateTime.DateParse(testday)) > (month) Then
    '                    If DateTime.GetDayOfWeek(DateTime.DateParse(testday)) = 2 Then
    '                        i=7
    '                        Exit
    '                    End If
    '                End If
    '            End If
            #end region
            Dim query As String ="select count(*) from calendars where userid='" & idlogin & "' and dateapp='" & DateTime.Date( DateTime.DateParse(iniziosettimanadelmese)+(DateTime.TicksPerDay*(i))) & "' ORDER BY dateapp;"
            Dim dds As Int = DateTime.GetDayOfMonth(DateTime.DateParse(iniziosettimanadelmese)+(DateTime.TicksPerDay*(i)))
            If ss= 1 Then
                If CreateBarData(BarChart1) = True Then
                    sqliteexecuty(sqlite,query,BarChart1,dds)
                    Log(dds)
                End If
            End If
            If ss= 2 Then
                If CreateBarData(BarChart2) = True Then
                    sqliteexecuty(sqlite,query,BarChart2,dds)
                    Log(dds)
                End If
            End If
            If ss= 3 Then
                If CreateBarData(BarChart3) = True Then
                    sqliteexecuty(sqlite,query,BarChart3,dds)
                    Log(dds)
                End If
            End If
            If ss= 4 Then
                If CreateBarData(BarChart4) = True Then
                    sqliteexecuty(sqlite,query,BarChart4,dds)
                    Log(dds)
                End If
            End If
            If ss= 5 Then
                If CreateBarData(BarChart5) = True Then
                    sqliteexecuty(sqlite,query,BarChart5,dds)
                    Log(dds)
                End If
            End If
            If ss= 6 Then
                If CreateBarData(BarChart1) = True Then
                    sqliteexecuty(sqlite,query,BarChart6,dds)
                    Log(dds)
                End If
            End If
        Next
        iniziosettimanadelmese=DateTime.Date( DateTime.DateParse(iniziosettimanadelmese)+(DateTime.TicksPerDay*(7)))
    Next

  
End Sub

Sub sqliteexecuty(sqlite As SQL, query As String, chart As xChart, dd As String)
  
    Dim rs As ResultSet
    Dim SenderFilter As Object = sqlite.ExecQueryAsync("SQL", query, Null)
    Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, rs As ResultSet)
    Try
        If Success Then
            Do While rs.NextRow
                Dim value As Double = rs.GetString2(0)
                chart.AddBarMultiplePoint(dd, Array As Double(value))
                chart.DrawChart
                rs.Close
            Loop
            rs.Close
        Else
            Log(LastException)
        End If
    Catch
        Log(LastException)
    End Try
  
End Sub

Private Sub CreateBarData(chart As xChart) As Boolean

    chart.ClearData
    chart.Title= ""
    chart.ChartType="BAR"
    chart.XAxisName = ""
    chart.YAxisName = ""
    chart.DrawHorizontalGridLines=False
    chart.DrawVerticalGridLines=False
    chart.AutomaticScale=True
    chart.AutomaticTextSizes=True
    chart.ChartBackgroundColor=xui.Color_ARGB(255,50,50,50)
    chart.AddBar("", xui.Color_ARGB(255,200,100,0))
    chart.XScaleTextOrientation = "HORIZONTAL"
    Return True
  
End Sub

Sub Button3_MouseClicked (EventData As MouseEvent)
    count_Item_Calendar_for_week
End Sub

Sub Button2_MouseClicked (EventData As MouseEvent)
    count_Item_Calendar_For_Month
End Sub

Sub Button1_MouseClicked (EventData As MouseEvent)
    If CreateBarData(xChart2) = True Then
      
    End If
End Sub
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
ho un piccolo problema che mi fa diventare femmina che sclera
Hai la fortuna che qui non capitino delle femministe 😄


( i Nomi delle variabili sono alla cxxxo perchè prima di montare il tutto nell'app voglio testare bene il cdice)
Tutte scuse e questa non vale granché! Parafrasando Nanni Moretti e la sua: "Le parole sono importanti"... I nomi delle variabili sono importanti! Meglio usare subito nomi decenti, anziché cambiarli in un secondo tempo.


@dragonblu19 qui puoi prendere degli spunti
In questo periodo (e per i prossimi 2 anni almeno!) è importante non prendere... sputi!


Prima che io ammattisca (o meglio, finisca di ammattire) leggendo tutto il tuo codice:

1 - se hai pubblicato tutto il codice, tanto vale che alleghi il progetto, così faremmo prima (meglio e più facilmente) a darti una mano;
2 - visto il tipo di problema che hai (ma anche molto spesso) il modo migliore per risolverlo è... indovina; te lo scrivo in uno spoiler, tu prima prova a pensarci, a "rispondere" a questa mia domanda (dentro di te):
A - mettere un breakpoint in un punto cruciale della fase in esame;
B - continuare a far andare avanti il programma, premendo F8, ovvero eseguendo una riga per volta;
C - controllare i valori delle variabili, scrivendo dei Log e/o guardandone il contenuto nella finestra che compare quando passi il cursore sul nome di una variabile e magari usando anche la finestra di debug.
 

ivanomonti

Expert
Licensed User
Longtime User
@LucaMs, ho postato il mio codice ma il progetto e composta da una classe di oltre 4000 righe e un database che dovrei mettere su un drive, ma a parte questo che non mi sebra il caso di fare tutto questo trasbusco per avere dei consigli, se proprio serve e nel frattempo non risolvo seguirò il tuo consiglio.

debag faccio sempre e al momento non trovo errori perchè non ne genera se non il caso rrandomico delle date, quindi il problema che ho visto da subito ma con i vari log le date cascano tutte in fila e precise, idem le query.

ora mi rimane solo verificare se i chart non tengono in memoria vecchi dati,,, che potrebbe essere e sto verificando, altro i tempi di risposta di sqlite sono molto più lenti del dovuto.

per i nomi delle variabili sono daccordo con te ma quando ho iniziato questo processo ero ancora dubbioso se scriverlo o no, ma la signora che vive di appuntamenti mi ha chiesto di farlo per lei e quindi lo sto facendo con poca incentivazione anche se come idea (poi rivista da me) e vincente perchè apre altri nuovi scenari.

un detto diceva,,, "davanti a un problema non porre un problema, ma una soluzione"
 

LucaMs

Expert
Licensed User
Longtime User
un detto diceva,,, "davanti a un problema non porre un problema, ma una soluzione"
Mai sentito. Comunque, la soluzione te l'ho data: nel tuo caso dovrebbe essere sufficiente un facile debugging, per scovare il problema.

Cmq, visto che non ti piacciono le mie risposte, tanto da giudicarle un problema in più, mi astengo :p
(molto meglio, non ho più tempo da sprecare, l'ho fatto fin troppo - in generale, eh, non relativamente alle risposte date a te).
 

ivanomonti

Expert
Licensed User
Longtime User
@LucaMs non era riferito a te ma a me, cmq sia non voglio forzare la mano, mi sono appena rimesso a fare debug come sempre e vedo che le query sono tutte in fila ad ogni click...


B4X:
2020
4
1
aprile
mercoledì
-----------------------
select count(*) from calendars where userid='20200425171020' and dateapp='2020-03-31' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-01' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-02' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-03' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-04' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-05' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-06' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-07' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-08' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-09' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-10' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-11' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-12' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-13' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-14' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-15' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-16' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-17' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-18' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-19' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-20' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-21' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-22' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-23' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-24' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-25' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-26' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-27' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-28' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-29' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-04-30' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-05-01' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-05-02' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-05-03' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-05-04' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-05-05' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-05-06' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-05-07' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-05-08' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-05-09' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-05-10' ORDER BY dateapp;
select count(*) from calendars where userid='20200425171020' and dateapp='2020-05-11' ORDER BY dateapp;

ma i dati vanno sempre per i fatti loro, LucaMs ripeto non sei obligato a rispondere, io condivido per passione del codice poi chi risponde bene o rimane un post vuoto ;-)
 

ivanomonti

Expert
Licensed User
Longtime User
il for non dava il tempo e quindi le risposte arrivano da sqlite in tempi diversi e sparsi, cambiato il codice e messo un return true e tutto procede a meraviglia.

B4X:
Sub sqliteexecuty(sqlite As SQL, query As String, chart As xChart, dd As String) As Boolean
    
    Dim rs As ResultSet
    rs = sqlite.ExecQuery(query)
    
    Try
        Do While rs.NextRow
            Dim value As Double = rs.GetString2(0)
            chart.AddBarMultiplePoint(dd, Array As Double(value))
            chart.DrawChart
            MapList.Add(value)
        Loop
    Catch
        rs.Close
        Log(LastException)
    End Try
    
    Return True
    
End Sub
 

ivanomonti

Expert
Licensed User
Longtime User
Il punto è che in quel caso non c'è differenza, perché non è certamente quello che ti ha risolto il problema; devi aver fatto altro, che lo ha risolto.

No la risposta Async continua nel suo loop e ha tempi di risposta diversi ma essendo resumabile lascia che il codice continui il suo da fare (se ho capito bene il resumabile)


l'errore (per modo di dire):
Dim SenderFilter As Object = sqlite.ExecQueryAsync("SQL", query, Null)
    Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, rs As ResultSet)

in questo modo il codice è obbligato ad attendere il return prima di inviare la prossima richiesta, quindi la prossima query partedopo la risposta ricevuta


codice cambiato:
Dim rs As ResultSet
    rs = sqlite.ExecQuery(query)


nel primo caso va bene se non devo mantenere un ordine preciso e credo sia più sicura da un lato, nel secondo step obbligo attese e pertanto potrebbe risultare più lento, in termini di sicurezza in una mora di lavoro esagerata non saprei, intendo dire se la rete si blocca o cosa che conclusioni mi devo aspettare.

ma il codice cambiato e solo questo
 

ivanomonti

Expert
Licensed User
Longtime User
@Star-Dust, ho scritto una frase che diceva,,, "davanti a un problema non porre un problema, ma una soluzione" nel momento sbagliato, come se volessi dire dammi la soluzione e non rompere i coglioni hahhah ma era una mia riflessione.
 

Star-Dust

Expert
Licensed User
Longtime User
@Star-Dust, ho scritto una frase che diceva,,, "davanti a un problema non porre un problema, ma una soluzione" nel momento sbagliato, come se volessi dire dammi la soluzione e non rompere i coglioni hahhah ma era una mia riflessione.
Beh non posso biasimarti, lo avrei scritto anche io ma meno poeticamente 😂 😂 😂 😂
 
Top