TableData.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5457 4417adcb02b1
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5380
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
     1
"
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
     2
 COPYRIGHT (c) 2018 by eXept Software AG
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
     3
              All Rights Reserved
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
     4
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
     5
 This software is furnished under a license and may be used
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
     6
 only in accordance with the terms of that license and with the
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
     8
 be provided or otherwise made available to, or used by, any
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
     9
 other person.  No title to or ownership of the software is
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
    10
 hereby transferred.
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
    11
"
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"{ NameSpace: Smalltalk }"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
Object subclass:#TableData
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	instanceVariableNames:'rowData columnNames columnTypes tableName'
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	classVariableNames:''
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
4973
084da8f61316 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4971
diff changeset
    20
	category:'Collections-Sequenceable-Table'
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!TableData class methodsFor:'documentation'!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
5380
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
    25
copyright
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
    26
"
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
    27
 COPYRIGHT (c) 2018 by eXept Software AG
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
    28
              All Rights Reserved
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
    29
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
    30
 This software is furnished under a license and may be used
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
    31
 only in accordance with the terms of that license and with the
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
    33
 be provided or otherwise made available to, or used by, any
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
    34
 other person.  No title to or ownership of the software is
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
    35
 hereby transferred.
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
    36
"
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
    37
!
1853a5daf733 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5233
diff changeset
    38
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
documentation
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
    40
"   Unfinished
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    Ongoing work to support some algorithms on table data (such as CSV files).
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
    Snippets to read and process tabular (CSV) data
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
    44
    Snippets to generate a plot.
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
    46
    The category DWD (Deutscher Wetter Dienst / German weather service)
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
    47
    contains specific code to deal with historic weather data.
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    48
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    49
    plot requires the r language to be installed (uses 'r' command).
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    50
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
    [author:]
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
        Claus Gittinger
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
    [instance variables:]
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
        rowData                 the actual data
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
        columnNames             name per column 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
        columnTypes             type per column (default is String)
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
        tableName               name - only used for labeling graphs
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
        
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
    [class variables:]
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
    [see also:]
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
"
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    65
!
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    66
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    67
examples
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    68
"  
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    69
     self new 
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    70
        readCSV:'/Users/exept/Downloads/masie_4km_allyears_extent_sqkm.csv';
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    71
        inspect.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    72
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    73
     ((self new 
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    74
        readCSV:'/Users/exept/Downloads/masie_4km_allyears_extent_sqkm.csv' separator:$, skip:1)
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    75
            masie_meanPerMonthOfColumnNamed:'(0) Northern_Hemisphere')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    76
                plot
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    77
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    78
     '/tmp/xxx.csv' asFilename writingFileDo:[:s |
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    79
        ((self new 
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    80
            readCSV:'/Users/exept/Downloads/masie_4km_allyears_extent_sqkm.csv' separator:$, skip:1)
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    81
                masie_meanPerMonthOfColumnNamed:'(0) Northern_Hemisphere')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    82
                    writeCSVToStream:s
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
    83
      ]  
5233
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
    84
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
    85
     |data tmax|
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
    86
     data := self fromFile:'/Users/exept/Desktop/klima/monatswerte_KL_04927_17920101_19840731_hist/produkt_klima_monat_17920101_19840731_04927.txt'.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
    87
     tmax := data withColumnsNamed:#('MESS_DATUM_BEGINN' 'MO_TT').
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
    88
     tmax tableName:'Stuttgart 04927'.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
    89
     tmax plot:{ #x -> 'MESS_DATUM_BEGINN' . #y -> { 'MO_TT'  }}.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
    90
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
    91
     |data|
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
    92
     data := self fromFile:'/Users/exept/Desktop/klima/monatswerte_KL_04927_17920101_19840731_hist/produkt_klima_monat_17920101_19840731_04927.txt'.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
    93
     data := data withColumnsNamed:#('MESS_DATUM_BEGINN' 'MO_TT').
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
    94
     data := data dwd_meanPerYearOfColumnNamed:'MO_TT'.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
    95
     data tableName:'Stuttgart 04927'.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
    96
     data plot:{ #x -> 'MESS_DATUM' . #y -> { 'Mean_Per_Year_MO_TT'  }}.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
    97
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
    98
     |data|
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
    99
     data := self fromFile:'/Users/exept/Desktop/klima/monatswerte_KL_05792_19000801_20181231_hist/produkt_klima_monat_19000801_20181231_05792.csv'.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   100
     data := data withColumnsNamed:#('MESS_DATUM_BEGINN' 'MO_TT').
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   101
     data := data dwd_meanPerYearOfColumnNamed:'MO_TT'.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   102
     data tableName:'Zugspitze 04927'.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   103
     data plot:{ #x -> 'MESS_DATUM' . #y -> { 'Mean_Per_Year_MO_TT'  }}.
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   104
"
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
! !
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
!TableData class methodsFor:'instance creation'!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
fromFile:filename
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
    ^ self new readCSV:filename
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
     self fromFile:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt'
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
    "Created: / 06-01-2019 / 13:28:53 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
    "Modified: / 09-01-2019 / 12:08:02 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
rows:rowData columnNames:names
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
    ^ self new rows:rowData columnNames:names
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
    "Created: / 06-01-2019 / 13:25:37 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
rows:rowData columnNames:names tableName:tableName
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
    ^ self new rows:rowData columnNames:names tableName:tableName
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
    "Created: / 06-01-2019 / 19:24:47 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
! !
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
!TableData methodsFor:'accessing'!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
getColumn:index
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   135
    "return a column (by index) as a vector"
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
    ^ rowData collect:[:row | row at:index].
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
     self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
        getColumn:1.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
    "Created: / 06-01-2019 / 19:04:08 / Claus Gittinger"
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   146
    "Modified (comment): / 30-05-2019 / 11:29:54 / Claus Gittinger"
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
getColumnNamed:name
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   150
    "return a column (by name) as a vector"
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   151
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
    ^ self getColumn:(self indexOfColumnNamed:name)
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
     self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
        getColumnNamed:'TXK'.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
    "/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
    "Created: / 06-01-2019 / 19:04:24 / Claus Gittinger"
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   163
    "Modified (comment): / 30-05-2019 / 11:30:00 / Claus Gittinger"
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
getColumns:indexCollection
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   167
    "return multiple columns (by index vector) as a vector of columns"
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   168
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
    ^ rowData collect:[:row | 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
        indexCollection collect:[:eachColIdx | row at:eachColIdx] as:Array.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
    ].        
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
     self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
        getColumns:#(1 2 3).
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
    "Created: / 06-01-2019 / 19:04:47 / Claus Gittinger"
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   180
    "Modified (comment): / 30-05-2019 / 11:30:30 / Claus Gittinger"
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
getColumnsNamed:names
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   184
    "return multiple columns (by name vector) as a vector of columns"
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   185
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
    |colsIndices|
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
    colsIndices := names collect:[:eachName | self indexOfColumnNamed:eachName].
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
    ^ self getColumns:colsIndices
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
     self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
        getColumnsNamed:#('MESS_DATUM' 'TXK' 'TNK').
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
    "/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
    "Created: / 06-01-2019 / 19:04:56 / Claus Gittinger"
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   200
    "Modified (comment): / 30-05-2019 / 11:30:41 / Claus Gittinger"
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
tableName:aString
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   204
    "set the table's name"
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   205
    
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
    tableName := aString.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   208
    "Modified (comment): / 30-05-2019 / 11:30:52 / Claus Gittinger"
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
tableNamePrefix:aString
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   212
    "prepend a prefix to the table's name"
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   213
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
    tableName := aString,tableName.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
    "Created: / 06-01-2019 / 21:13:12 / Claus Gittinger"
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   217
    "Modified (comment): / 30-05-2019 / 11:31:08 / Claus Gittinger"
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
tableNameSuffix:aString
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   221
    "append a suffix to the table's name"
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   222
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
    tableName := tableName,aString.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
    "Created: / 06-01-2019 / 21:13:01 / Claus Gittinger"
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   226
    "Modified (comment): / 30-05-2019 / 11:31:17 / Claus Gittinger"
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
! !
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
!TableData methodsFor:'analysis'!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
addBincoSlidingMean3ForColumnNamed:colName
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
    "add a column with the sliding binco mean (1/4 + 1/2 + 1/4).
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
     As binco:3 is quite common,
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
     that is a tuned version of addBincoSlidingMean:3 forColumnNamed:colName"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
    | outRows valColIdx prevRow firstIndex lastIndex meanColIdx|
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
    valColIdx := self indexOfColumnNamed:colName.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
    outRows := OrderedCollection new.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
    prevRow := nil.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
    firstIndex := 1. lastIndex := rowData size.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
    rowData := rowData collectWithIndex:[:row :idx|
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
        |slidingSum|
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
        ((idx > firstIndex) and:[idx < lastIndex]) ifTrue:[
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
            slidingSum := (
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
                               ((rowData at:idx-1) at:valColIdx)
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
                             + (((rowData at:idx) at:valColIdx)*2)
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
                             + ((rowData at:idx+1) at:valColIdx)
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
                          ) / 4.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
        ].
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
        row copyWith:slidingSum.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
    ].
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
    meanColIdx := columnNames size+1.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
    (rowData at:firstIndex) at:meanColIdx put:((rowData at:firstIndex+1) at:meanColIdx).
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
    (rowData at:lastIndex) at:meanColIdx put:((rowData at:lastIndex-1) at:meanColIdx).
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
    columnNames := columnNames copyWith:('Sliding_Binco_Mean_of_',colName).
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
    ^ self 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
     (((self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
            meanPerYearOfColumnNamed:'TXK')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
                addBincoSlidingMean3ForColumnNamed:'Mean_Per_Year_TXK')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
                    tableName:'Feldberg/Schwarzwald';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
                    plot:{ #x -> 'MESS_DATUM' . #y -> { 'Mean_Per_Year_TXK' . 'Sliding_Binco_Mean_of_Mean_Per_Year_TXK' .  }}.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
        
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
    "/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
    "Created: / 08-01-2019 / 00:10:16 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
    "Modified (comment): / 09-01-2019 / 12:32:34 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   276
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
addBincoSlidingMean:n forColumnNamed:colName
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   278
    "add a column with the sliding binco mean (1/2^n + ... + 1/4 + 1/2 + 1/4 + ... + 1/2^n)"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
    |nH outRows valColIdx prevRow firstIndex lastIndex meanColIdx wAll|
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   282
    self assert:(n odd).
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
    nH := n // 2.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   284
    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
    valColIdx := self indexOfColumnNamed:colName.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   286
    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   287
    outRows := OrderedCollection new.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   288
    prevRow := nil.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   289
    firstIndex := 1+nH. lastIndex := rowData size-nH.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   290
    wAll := 0.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   291
    1 to:nH do:[:delta |
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   292
        wAll := wAll + (1 / (2 raisedTo:delta)).    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   293
        wAll := wAll + (1 / (2 raisedTo:delta)).    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
    ].
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
    wAll := wAll + 1.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   296
    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   297
    rowData := rowData collectWithIndex:[:row :idx|
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   298
        |slidingSum|
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   299
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   300
        ((idx >= firstIndex) and:[idx <= lastIndex]) ifTrue:[
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   301
            slidingSum := 0.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   302
            "/ ... /8 /4 /2 /1 /2 /4 /8 ...
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   303
            1 to:nH do:[:delta |
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   304
                slidingSum := slidingSum + (((rowData at:idx-delta) at:valColIdx) / (2 raisedTo:delta)).    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   305
                slidingSum := slidingSum + (((rowData at:idx+delta) at:valColIdx) / (2 raisedTo:delta)).    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   306
            ].
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   307
            slidingSum := slidingSum + ((rowData at:idx) at:valColIdx).
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   308
            slidingSum := slidingSum / wAll.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   309
        ].
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   310
        row copyWith:slidingSum.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   311
    ].
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   312
    meanColIdx := columnNames size+1.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   313
    1 to:nH do:[:delta |
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   314
        (rowData at:0+delta) at:meanColIdx put:((rowData at:nH+1) at:meanColIdx)
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   315
    ].
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   316
    1 to:nH do:[:delta |
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   317
        (rowData at:rowData size+1-delta) at:meanColIdx put:((rowData at:rowData size-nH-1) at:meanColIdx)
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   318
    ].
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   319
    columnNames := columnNames copyWith:('Sliding_Binco_Mean_of_',colName).
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
    ^ self 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
     (((self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   324
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   325
            meanPerYearOfColumnNamed:'TXK')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
                addBincoSlidingMean:5 forColumnNamed:'Mean_Per_Year_TXK')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   327
                    tableName:'Feldberg/Schwarzwald';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   328
                    plot:{ #x -> 'MESS_DATUM' . 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
                           #y -> { 'Mean_Per_Year_TXK' . 'Sliding_Binco_Mean_of_Mean_Per_Year_TXK' .  }}.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
        
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
    "/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
    "Created: / 07-01-2019 / 15:37:16 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
    "Modified (comment): / 09-01-2019 / 12:22:31 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
addSlidingMean:n forColumnNamed:colName
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
    "add a column with the sliding mean.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   341
     The sliding mean looks meaner, but may introduce lag (phase shift),
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   342
     which binco avoids."
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
    |slidingValues slidingSum outRows valColIdx prevYear sum countDaysPerYear|
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
    valColIdx := self indexOfColumnNamed:colName.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   347
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   348
    "/ take the the first n values as initial sliding mean
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   349
    slidingValues := (1 to:n) collect:[:rowIdx | (rowData at:rowIdx) at:valColIdx] as:OrderedCollection.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   350
    slidingSum := slidingValues sum.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   351
    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   352
    outRows := OrderedCollection new.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   353
    prevYear := nil.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   354
    sum := countDaysPerYear := 0.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
    rowData := rowData collect:[:row |
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   356
        | rowsDate rowsYear val|
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   357
        
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   358
        slidingSum := slidingSum - slidingValues first.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   359
        slidingValues removeFirst.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   360
        slidingValues add:(row at:valColIdx).
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   361
        slidingSum := slidingSum + slidingValues last.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   362
        row copyWith:(slidingSum / n).
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   363
    ].
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   364
    columnNames := columnNames copyWith:('Sliding_Mean_of_',colName).
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
    ^ self 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   366
    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   367
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   368
     (((self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   369
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   370
            meanPerYearOfColumnNamed:'TXK')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   371
                addSlidingMean:11 forColumnNamed:'Mean_Per_Year_TXK')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   372
                    tableName:'Feldberg/Schwarzwald';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   373
                    plot:{ #x -> 'MESS_DATUM' . #y -> { 'Mean_Per_Year_TXK' . 'Sliding_Mean_of_Mean_Per_Year_TXK' .  }}.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   374
        
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   375
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   376
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   377
    "/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   378
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   379
    "Created: / 06-01-2019 / 20:05:42 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   380
    "Modified (comment): / 09-01-2019 / 12:33:16 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   381
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   383
extractRowsWhere:filterBlock
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   384
    "return a new table containing only rows for which filterBlock evaluates to true"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   385
    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   386
    |outRows|
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   387
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   388
    outRows := rowData select:filterBlock.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   389
    ^ self class 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   390
        rows:outRows columnNames:columnNames
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   391
    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   392
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   393
     (((self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   394
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
            meanPerMonthOfColumnNamed:'TXK')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
                extractRowsWhere:[:row | (row at:1) startsWith:'1945'])
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   397
                    plot
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   398
        
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   399
     (((self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   400
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   401
            meanPerMonthOfColumnNamed:'TXK')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   402
                extractRowsWhere:[:row | ((row at:1) from:5 to:6) = '01'])
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   403
                    plot
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   404
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   405
     (((self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   406
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   407
            meanPerMonthOfColumnNamed:'TXK')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   408
                extractMonth:8)
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   409
                    plot
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   410
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   411
     (((self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   412
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   413
            meanPerMonthOfColumnNamed:'TXK')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   414
                extractMonth:9)
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   415
                    plot
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   416
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   417
     (((self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   418
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   419
            meanPerMonthOfColumnNamed:'TXK')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   420
                extractMonth:10)
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   421
                    plot
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   422
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   423
     (((self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   424
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19530101_20171231_04931.txt')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   425
            meanPerMonthOfColumnNamed:'TXK')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   426
                extractMonth:10)
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   427
                    tableNameSuffix:'-Echterdingen';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   428
                    plot
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   429
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   430
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   431
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   432
    "/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   433
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
    "Created: / 09-01-2019 / 12:35:44 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   435
! !
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   436
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   437
!TableData methodsFor:'analysis - DWD'!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   438
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   439
dwd_extractMonth:monthIndex
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   440
    "return a new table containing only rows for that month.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   441
     This is specific to DWD data"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   442
    
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   443
    ^ self dwd_extractMonth:monthIndex columnName:'MESS_DATUM' format:'%4y%2m%2d'
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   444
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   445
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   446
     (((self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   447
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   448
            dwd_meanPerMonthOfColumnNamed:'TXK')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   449
                dwd_extractMonth:1 columnName:'MESS_DATUM' format:'%4y%2m')
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   450
                    plot
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   451
        
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
     (((self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   453
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   454
            dwd_meanPerMonthOfColumnNamed:'TXK')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   455
                dwd_extractMonth:2 columnName:'MESS_DATUM' format:'%4y%2m')
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   456
                    plot
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   457
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   458
     (((self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   459
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   460
            dwd_meanPerMonthOfColumnNamed:'TXK')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   461
                dwd_extractMonth:8 columnName:'MESS_DATUM' format:'%4y%2m')
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   462
                    plot
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   463
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   464
     (((self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   465
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   466
            dwd_meanPerMonthOfColumnNamed:'TXK')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   467
                dwd_extractMonth:9 columnName:'MESS_DATUM' format:'%4y%2m')
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   468
                    plot
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   469
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   470
     (((self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   471
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   472
            dwd_meanPerMonthOfColumnNamed:'TXK')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   473
                dwd_extractMonth:10 columnName:'MESS_DATUM' format:'%4y%2m')
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   474
                    plot
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   475
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   476
     (((self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   477
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19530101_20171231_04931.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   478
            dwd_meanPerMonthOfColumnNamed:'TXK')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   479
                dwd_extractMonth:10 columnName:'MESS_DATUM' format:'%4y%2m')
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   480
                    tableNameSuffix:'-Echterdingen';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   481
                    plot
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   482
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   483
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   484
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   485
    "/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   486
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   487
    "Created: / 06-01-2019 / 19:00:52 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   488
    "Modified (comment): / 09-01-2019 / 18:30:09 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   489
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   490
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   491
dwd_extractMonth:monthIndex columnName:monthColumnName
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   492
    "return a new table containing only rows for that month.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   493
     This is specific to DWD data"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   494
    
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   495
    ^ self dwd_extractMonth:monthIndex columnName:monthColumnName format:'%4y%2m%2d'
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   496
    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   497
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   498
     (((self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   499
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   500
            dwd_meanPerMonthOfColumnNamed:'TXK')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   501
                dwd_extractMonth:1 columnName:'MESS_DATUM' format:'%4y%2m')
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   502
                    plot
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   503
        
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   504
     (((self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   505
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   506
            dwd_meanPerMonthOfColumnNamed:'TXK')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   507
                dwd_extractMonth:2 columnName:'MESS_DATUM' format:'%4y%2m')
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   508
                    plot
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   509
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   510
     (((self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   511
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   512
            dwd_meanPerMonthOfColumnNamed:'TXK')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   513
                dwd_extractMonth:8 columnName:'MESS_DATUM' format:'%4y%2m')
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   514
                    plot
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   515
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   516
     (((self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   517
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   518
            dwd_meanPerMonthOfColumnNamed:'TXK')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   519
                dwd_extractMonth:9 columnName:'MESS_DATUM' format:'%4y%2m')
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   520
                    plot
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   521
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   522
     (((self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   523
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   524
            dwd_meanPerMonthOfColumnNamed:'TXK')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   525
                dwd_extractMonth:10 columnName:'MESS_DATUM' format:'%4y%2m')
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   526
                    plot
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   527
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   528
     (((self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   529
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19530101_20171231_04931.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   530
            dwd_meanPerMonthOfColumnNamed:'TXK')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   531
                dwd_extractMonth:10 columnName:'MESS_DATUM' format:'%4y%2m')
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   532
                    tableNameSuffix:'-Echterdingen';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   533
                    plot
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   534
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   535
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   536
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   537
    "/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   538
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   539
    "Created: / 09-01-2019 / 14:42:05 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   540
    "Modified (comment): / 09-01-2019 / 18:31:31 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   541
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   542
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   543
dwd_extractMonth:monthIndex columnName:monthColumnName format:dateFormat
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   544
    "return a new table containing only rows for that month.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   545
     This is specific to DWD data"
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   546
    
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   547
    |dateColIdx|
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   548
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   549
    dateColIdx := self indexOfColumnNamed:monthColumnName.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   550
    ^ (self 
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   551
        extractRowsWhere:[:row | 
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   552
            | rowsDate rowsYearAndMonth val|
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   553
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   554
            rowsDate := Date readFrom:(row at:dateColIdx) format:dateFormat.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   555
            rowsDate month = monthIndex
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   556
        ])
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   557
        tableName:(Date nameOfMonth:monthIndex),' Mean'
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   558
    
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   559
    "
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   560
     (((self new 
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   561
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   562
            dwd_meanPerMonthOfColumnNamed:'TXK')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   563
                dwd_extractMonth:1 columnName:'MESS_DATUM' format:'%4y%2m')
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   564
                    plot
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   565
        
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   566
     (((self new 
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   567
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   568
            dwd_meanPerMonthOfColumnNamed:'TXK')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   569
                dwd_extractMonth:2 columnName:'MESS_DATUM' format:'%4y%2m')
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   570
                    plot
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   571
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   572
     (((self new 
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   573
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   574
            dwd_meanPerMonthOfColumnNamed:'TXK')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   575
                dwd_extractMonth:8 columnName:'MESS_DATUM' format:'%4y%2m')
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   576
                    plot
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   577
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   578
     (((self new 
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   579
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   580
            dwd_meanPerMonthOfColumnNamed:'TXK')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   581
                dwd_extractMonth:9 columnName:'MESS_DATUM' format:'%4y%2m')
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   582
                    plot
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   583
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   584
     (((self new 
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   585
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   586
            dwd_meanPerMonthOfColumnNamed:'TXK')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   587
                dwd_extractMonth:10 columnName:'MESS_DATUM' format:'%4y%2m')
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   588
                    plot
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   589
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   590
     (((self new 
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   591
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19530101_20171231_04931.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   592
            dwd_meanPerMonthOfColumnNamed:'TXK')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   593
                dwd_extractMonth:10 columnName:'MESS_DATUM' format:'%4y%2m')
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   594
                    tableNameSuffix:'-Echterdingen';
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   595
                    plot
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   596
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   597
     (((self new 
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   598
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19530101_20171231_04931.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   599
            dwd_meanPerMonthOfColumnNamed:'TXK')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   600
                dwd_extractMonth:3 columnName:'MESS_DATUM' format:'%4y%2m')
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   601
                    tableNameSuffix:'-Echterdingen';
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   602
                    plot
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   603
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   604
     |table|
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   605
     table := (self new 
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   606
            readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19530101_20171231_04931.txt').
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   607
     1 to:12 do:[:month |        
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   608
         ((table
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   609
                dwd_meanPerMonthOfColumnNamed:'TXK')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   610
                    dwd_extractMonth:month columnName:'MESS_DATUM' format:'%4y%2m')
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   611
                        tableNameSuffix:'-Echterdingen';
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   612
                        plot
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   613
     ]
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   614
    "
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   615
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   616
    "/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   617
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   618
    "Created: / 09-01-2019 / 18:27:28 / Claus Gittinger"
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   619
!
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   620
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   621
dwd_extractMonth:month day:day
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   622
    "return a new table containing only rows for that day in month"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   623
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   624
    ^ self dwd_extractMonth:month day:day columnName:'MESS_DATUM' format:'%4y%2m%2d'
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   625
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   626
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   627
     ((self fromFile:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   628
        dwd_extractMonth:1 day:1)
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   629
            tableName:'1st Januar, Feldberg';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   630
            plot:{ #x -> 'MESS_DATUM' . #y -> { 'TXK' . 'TNK' }}
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   631
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   632
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   633
    "/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   634
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   635
    "Created: / 06-01-2019 / 13:15:46 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   636
    "Modified (comment): / 10-01-2019 / 16:20:48 / Claus Gittinger"
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   637
!
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   638
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   639
dwd_extractMonth:month day:day columnName:monthColumnName format:dateFormat
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   640
    "return a new table containing only rows for that day in month"
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   641
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   642
    |outRows dateColIdx|
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   643
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   644
    dateColIdx := self indexOfColumnNamed:monthColumnName.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   645
    outRows := rowData select:[:row |
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   646
        |rowsDate|
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   647
        
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   648
        rowsDate := Date readFrom:(row at:dateColIdx) format:dateFormat.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   649
        (rowsDate month = month) and:[rowsDate day = day].
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   650
    ].
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   651
    ^ self class rows:outRows columnNames:columnNames
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   652
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   653
    "
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   654
     ((self fromFile:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   655
        dwd_extractMonth:1 day:1 columnName:'MESS_DATUM' format:'%4y%2m%2d')
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   656
            plot:{ #x -> 'MESS_DATUM' . #y -> { 'TXK' . 'TNK' }}
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   657
    "
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   658
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   659
    "/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   660
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   661
    "Created: / 10-01-2019 / 16:14:29 / Claus Gittinger"
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   662
!
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   663
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   664
dwd_meanPerMonthOfColumnNamed:colName
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   665
    "return a new table containing the arithmetic mean per month of a column"
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   666
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   667
    |outRows valColIdx dateColIdx prevYearAndMonth sum countDaysPerMonth|
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   668
5233
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   669
    dateColIdx := self indexOfColumnNamed:'MESS_DATUM' ifAbsent:[self indexOfColumnNamed:'MESS_DATUM_BEGINN'].
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   670
    valColIdx := self indexOfColumnNamed:colName.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   671
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   672
    outRows := OrderedCollection new.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   673
    prevYearAndMonth := nil.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   674
    sum := countDaysPerMonth := 0.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   675
    rowData do:[:row |
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   676
        | rowsDate rowsYearAndMonth val|
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   677
        
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   678
        rowsDate := row at:dateColIdx.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   679
        "/ yyyymmdd
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   680
        rowsYearAndMonth := rowsDate copyTo:6.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   681
        prevYearAndMonth isNil ifTrue:[
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   682
            prevYearAndMonth := rowsYearAndMonth.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   683
            sum := countDaysPerMonth := 0.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   684
        ].
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   685
        (rowsYearAndMonth = prevYearAndMonth) ifTrue:[
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   686
            val := Number readFrom:(row at:valColIdx).
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   687
            sum := sum + val.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   688
            countDaysPerMonth := countDaysPerMonth + 1.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   689
        ] ifFalse:[
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   690
            outRows add:{ prevYearAndMonth . (sum / countDaysPerMonth) }.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   691
            sum := countDaysPerMonth := 0.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   692
            prevYearAndMonth := rowsYearAndMonth.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   693
        ].
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   694
    ].
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   695
    ^ self class 
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   696
        rows:outRows columnNames:{ 'MESS_DATUM' . 'Mean per month of ',colName }
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   697
        tableName:('Mean Per Month of ',colName)
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   698
    
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   699
    "
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   700
     ((self new 
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   701
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   702
            dwd_meanPerMonthOfColumnNamed:'TXK')
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   703
                plot
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   704
        
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   705
    "
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   706
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   707
    "/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   708
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   709
    "Created: / 06-01-2019 / 19:06:36 / Claus Gittinger"
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   710
    "Modified (comment): / 09-01-2019 / 12:24:34 / Claus Gittinger"
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   711
!
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   712
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   713
dwd_meanPerYearOfColumnNamed:colName
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   714
    "return a new table containing the arithmetic mean per year of a column"
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   715
5233
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   716
    |outRows valColIdx dateColIdx prevYear sum countValuesPerYear 
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   717
     prevVal mustFillPrevious mean|
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   718
5233
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   719
    dateColIdx := self indexOfColumnNamed:'MESS_DATUM' ifAbsent:[self indexOfColumnNamed:'MESS_DATUM_BEGINN'].
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   720
    valColIdx := self indexOfColumnNamed:colName.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   721
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   722
    outRows := OrderedCollection new.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   723
    prevYear := nil.
5233
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   724
    sum := countValuesPerYear := 0.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   725
    prevVal := nil.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   726
    mustFillPrevious := false.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   727
    rowData doWithIndex:[:row :rowIndex|
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   728
        | rowsDate rowsYear rowsMonth val|
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   729
        
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   730
        rowsDate := row at:dateColIdx.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   731
        "/ yyyymmdd
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   732
        rowsYear := rowsDate copyTo:4.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   733
        prevYear isNil ifTrue:[
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   734
            prevYear := rowsYear.
5233
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   735
            sum := countValuesPerYear := 0.
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   736
        ].
5233
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   737
        (rowsYear = prevYear) ifFalse:[
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   738
            "/ Jahreswechsel
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   739
            countValuesPerYear = 12 ifFalse:[
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   740
                "/ ignore if incomplete - take mean of prevyear and next year
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   741
                mustFillPrevious ifTrue:[self halt:'should not happen'].
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   742
                mustFillPrevious := true.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   743
                outRows add:{ prevYear . mean }.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   744
            ] ifTrue:[
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   745
                mean := sum / countValuesPerYear.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   746
                mustFillPrevious ifTrue:[
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   747
                    |t fillIn|
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   748
                    t := (outRows last at:2).
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   749
                    t isNil ifTrue:[
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   750
                        fillIn := mean
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   751
                    ] ifFalse:[
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   752
                        fillIn := (t+mean)/2
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   753
                    ].
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   754
                    outRows last at:2 put:fillIn
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   755
                ].
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   756
                outRows add:{ prevYear . mean }.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   757
                mustFillPrevious := false.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   758
            ].
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   759
            sum := countValuesPerYear := 0.
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   760
            prevYear := rowsYear.
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   761
        ].
5233
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   762
        val := Number readFrom:(row at:valColIdx).
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   763
        (val = -999) ifTrue:[
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   764
            |prevRow nextRow mean|
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   765
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   766
            "/ fill with arith. mean of previous value and next value
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   767
            prevRow := rowData at:rowIndex-1 ifAbsent:[row].
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   768
            nextRow := rowData at:rowIndex+1 ifAbsent:[row].
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   769
            mean := ((Number readFrom:(prevRow at:valColIdx)) + (Number readFrom:(nextRow at:valColIdx))) / 2.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   770
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   771
            val := mean.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   772
        ].
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   773
        sum := sum + val.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   774
        countValuesPerYear := countValuesPerYear + 1.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   775
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   776
        prevVal notNil ifTrue:[
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   777
            "/ ausreisser?
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   778
            (prevVal - val) abs > 20 ifTrue:[self halt].
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   779
        ].
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   780
        prevVal := val.
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   781
    ].
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   782
    ^ self class 
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   783
        rows:outRows columnNames:{ 'MESS_DATUM' . 'Mean_Per_Year_',colName }
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   784
        tableName:('Mean Per Year of ',colName)
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   785
    
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   786
    "
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   787
     ((self new 
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   788
        read:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   789
            dwd_meanPerYearOfColumnNamed:'TXK')
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   790
                plot
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   791
        
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   792
    "
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   793
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   794
    "/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   795
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   796
    "Created: / 06-01-2019 / 19:40:34 / Claus Gittinger"
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   797
    "Modified: / 06-01-2019 / 22:34:06 / Claus Gittinger"
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   798
! !
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   799
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   800
!TableData methodsFor:'analysis - masie'!
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   801
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   802
masie_meanPerMonthOfColumnNamed:colName
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   803
    "return a new table containing the arithmetic mean per month of a column
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   804
     of masie data"
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   805
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   806
    |outRows valColIdx dateColIdx prevMonth prevYearAndMonth sum countDaysPerMonth|
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   807
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   808
    dateColIdx := self indexOfColumnNamed:'yyyyddd'.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   809
    valColIdx := self indexOfColumnNamed:colName.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   810
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   811
    outRows := OrderedCollection new.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   812
    prevMonth := nil.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   813
    sum := countDaysPerMonth := 0.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   814
    rowData do:[:row |
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   815
        | date rowsDate rowsYear month rowsDay yearAndMonth rowsYearAndDay val |
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   816
        
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   817
        rowsDate := row at:dateColIdx.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   818
        "/ yyyyddd
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   819
        rowsYear := Integer readFrom:(rowsDate copyTo:4).
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   820
        rowsDay := Integer readFrom:(rowsDate copyFrom:5).
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   821
        date := Date newDay:rowsDay year:rowsYear.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   822
        month := date month.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   823
        yearAndMonth := '%4d%02d' printfWith:date year with:date month.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   824
        prevMonth isNil ifTrue:[
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   825
            prevMonth := month.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   826
            sum := countDaysPerMonth := 0.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   827
        ].
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   828
        (month = prevMonth) ifTrue:[
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   829
            val := Number readFrom:(row at:valColIdx).
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   830
            sum := sum + val.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   831
            countDaysPerMonth := countDaysPerMonth + 1.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   832
        ] ifFalse:[
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   833
            outRows add:{ prevYearAndMonth . (sum / countDaysPerMonth) }.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   834
            sum := countDaysPerMonth := 0.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   835
            prevYearAndMonth := yearAndMonth.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   836
            prevMonth := month.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   837
        ].
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   838
    ].
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   839
    ^ self class 
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   840
        rows:outRows columnNames:{ 'YearAndMonth' . 'Mean per month of ',colName }
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   841
        tableName:('Mean Per Month of ',colName)
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   842
    
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   843
    "
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   844
     ((self new 
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   845
        readCSV:'/Users/exept/Downloads/masie_4km_allyears_extent_sqkm.csv' separator:$, skip:1)
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   846
            masie_meanPerMonthOfColumnNamed:'(0) Northern_Hemisphere')
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   847
                plot
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   848
        
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   849
    "
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   850
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   851
    "Created: / 06-01-2019 / 19:06:36 / Claus Gittinger"
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   852
    "Modified (comment): / 09-01-2019 / 12:24:34 / Claus Gittinger"
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   853
! !
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   854
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   855
!TableData methodsFor:'helpers'!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   856
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   857
indexOfColumnNamed:name
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   858
    "find a column index by name"
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   859
    
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   860
    ^ columnNames indexOf:name ifAbsent:[self error:'no such column'].
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   861
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   862
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   863
     self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   864
        read:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   865
        indexOfColumnNamed:'MESS_DATUM'.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   866
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   867
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   868
    "/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   869
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   870
    "Created: / 06-01-2019 / 13:20:47 / Claus Gittinger"
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
   871
    "Modified (comment): / 30-05-2019 / 11:33:23 / Claus Gittinger"
5233
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   872
!
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   873
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   874
indexOfColumnNamed:name ifAbsent:exceptionValue
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   875
    "find a column index by name"
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   876
    
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   877
    ^ columnNames indexOf:name ifAbsent:exceptionValue.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   878
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   879
    "
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   880
     self new 
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   881
        read:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   882
        indexOfColumnNamed:'MESS_DATUM'.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   883
    "
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   884
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   885
    "/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   886
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   887
    "Created: / 06-01-2019 / 13:20:47 / Claus Gittinger"
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   888
    "Modified (comment): / 30-05-2019 / 11:33:23 / Claus Gittinger"
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   889
! !
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   890
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   891
!TableData methodsFor:'instance creation'!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   892
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   893
rows:rowDataArg columnNames:columnNamesArg
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   894
    rowData := rowDataArg.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   895
    columnNames := columnNamesArg.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   896
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   897
    "Created: / 06-01-2019 / 13:26:01 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   898
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   899
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   900
rows:rowDataArg columnNames:columnNamesArg tableName:tableNameArg
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   901
    rowData := rowDataArg.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   902
    columnNames := columnNamesArg.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   903
    tableName := tableNameArg.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   904
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   905
    "Created: / 06-01-2019 / 19:25:10 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   906
! !
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   907
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   908
!TableData methodsFor:'plotting'!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   909
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   910
plot
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   911
    self plot:nil
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   912
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   913
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   914
     |data tmax|
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   915
     
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   916
     data := self fromFile:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt'.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   917
     tmax := data withColumnsNamed:#('MESS_DATUM' 'TXK' 'TNK').
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   918
     tmax plot:{ #x -> 'MESS_DATUM' . #y -> { 'TXK' 'TNK' }} .
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   919
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   920
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   921
    "Created: / 06-01-2019 / 18:47:27 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   922
    "Modified: / 06-01-2019 / 21:32:22 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   923
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   924
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   925
plot:optionalSpec
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   926
    |tmpFile|
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   927
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   928
    [
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   929
        tmpFile := Filename newTemporary.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   930
        tmpFile writingFileDo:[:s |
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   931
            self writeCSVToStream:s.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   932
        ].
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   933
        "/ FileBrowserV2 openOn:tmpFile.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   934
        self plot:optionalSpec file:tmpFile.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   935
    ] ensure:[
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   936
        tmpFile delete
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   937
    ].
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   938
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   939
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   940
     |data tmax|
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   941
     
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   942
     data := self fromFile:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt'.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   943
     tmax := data withColumnsNamed:#('MESS_DATUM' 'TXK' 'TNK').
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   944
     tmax plot:{ #x -> 'MESS_DATUM' . #y -> { 'TXK' 'TNK' }} .
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   945
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   946
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   947
    "Created: / 06-01-2019 / 21:32:09 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   948
    "Modified: / 09-01-2019 / 18:40:16 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   949
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   950
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   951
plot:optionalSpec file:fileName
5233
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
   952
    |script scriptFile outFile width height spec xCol yCols cmd err|
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   953
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   954
    scriptFile := Filename newTemporary .
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   955
    outFile := '/tmp/plot3.png'.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   956
    outFile asFilename contents:''.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   957
    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   958
    width := 1200.
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
   959
    height := 800.
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   960
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   961
    optionalSpec notNil ifTrue:[
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   962
        spec := optionalSpec isDictionary 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   963
                    ifTrue:[optionalSpec] 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   964
                    ifFalse:[Dictionary withAssociations:optionalSpec].
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   965
        
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   966
        yCols := spec at:#y.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   967
        xCol := spec at:#x.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   968
        script := '
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   969
png(filename="%1", height=%3, width=%2)
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   970
Data <- read.csv(file="%4", header=TRUE, sep=";")
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   971
',xCol,' <- Data$',xCol,'
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   972
',((yCols collect:[:col | col,' <- Data$',col]) asStringWith:Character cr),
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   973
"/'plot(',xCol,', ' 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   974
"/       ,((yCols collect:[:col | col,', ']) asStringWith:''),
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   975
"/' type="l", main = "%5")'
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   976
'
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   977
',('plot(%1, %2, type="b", col=2, main = "%%5")' bindWith:xCol with:yCols first),'
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   978
',((yCols from:2 collect:[:ycol | 'lines(%1, %2, type="l", col=3)' bindWith:xCol with:ycol]) asStringWith:Character cr)
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   979
,'
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   980
# dev.off()
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   981
'
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   982
            bindWith:outFile 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   983
            with:width 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   984
            with:height
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   985
            with:fileName asFilename pathName
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   986
            with:(tableName ? '').
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   987
        "/ self halt.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   988
    ] ifFalse:[        
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   989
        script := '
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   990
# library(ggplot2)
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   991
# library(ggfortify)
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   992
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   993
png(filename="%1", height=%3, width=%2)
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   994
Data <- read.csv(file="%4", header=TRUE, sep=";")
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   995
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   996
# theme_set(theme_classic())
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   997
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   998
# Plot 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   999
# autoplot(Data) + 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1000
#   labs(title="Data") + 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1001
#   theme(plot.title = element_text(hjust=0.1))
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1002
plot(Data, type="l", main = "%5")
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1003
# plot(Data, cex = .4)
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1004
dev.off()
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1005
'
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1006
            bindWith:outFile 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1007
            with:width 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1008
            with:height
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1009
            with:fileName asFilename pathName
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1010
            with:(tableName ? '').
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1011
    ].
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1012
    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1013
    scriptFile contents:script.        
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1014
5233
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
  1015
    err := WriteStream on:String new.
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
  1016
    (OSProcess new 
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
  1017
        command:(cmd := 'r --silent --vanilla --slave -f %1' bindWith:scriptFile);
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
  1018
        errorStream:err;
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
  1019
        execute
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
  1020
    ) ifFalse:[
5457
4417adcb02b1 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5380
diff changeset
  1021
        self error:('cannot execute err: %1' bindWith: err contents)
5233
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
  1022
    ].
cdc7441f8520 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5232
diff changeset
  1023
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1024
    "/ self halt.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1025
    "/ outFile asFilename exists.
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
  1026
    ((Smalltalk classNamed:#Image) fromFile:outFile asFilename) inspect.
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1027
    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1028
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1029
     |data tmax|
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1030
     
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1031
     data := self fromFile:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt'.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1032
     tmax := data withColumnsNamed:#('MESS_DATUM' 'TXK').
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1033
     tmax tableName:'Feldberg'.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1034
     tmax plot:{ #x -> 'MESS_DATUM' . #y -> { 'TXK' . 'TNK' }}.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1035
    "
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1036
    "
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1037
     |data tmax|
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1038
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1039
     data := self fromFile:'/Users/exept/Desktop/klima/monatswerte_KL_01050_19240101_20181231_hist/produkt_klima_monat_19240101_20181231_01050.txt'.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1040
     tmax := data withColumnsNamed:#('MESS_DATUM_BEGINN' 'MO_TT').
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1041
     tmax tableName:'Feldberg'.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1042
     tmax plot:{ #x -> 'MESS_DATUM_BEGINN' . #y -> { 'MO_TT'  }}.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1043
    "
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1044
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1045
    "Created: / 06-01-2019 / 21:32:43 / Claus Gittinger"
4971
0bfb49cbcd3d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4789
diff changeset
  1046
    "Modified: / 30-05-2019 / 11:28:42 / Claus Gittinger"
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1047
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1048
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1049
plotFile:fileName
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1050
    self plot:nil file:fileName
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1051
    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1052
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1053
     |data tmax|
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1054
     
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1055
     data := self fromFile:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt'.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1056
     tmax := data withColumnsNamed:#('MESS_DATUM' 'TXK').
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1057
     tmax tableName:'Test'.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1058
     tmax plot.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1059
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1060
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1061
    "Created: / 06-01-2019 / 15:59:47 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1062
    "Modified: / 06-01-2019 / 21:32:59 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1063
! !
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1064
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1065
!TableData methodsFor:'processing'!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1066
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1067
removeColumn:index
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1068
    "destructively remove a column"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1069
    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1070
    columnNames := columnNames copyWithoutIndex:index.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1071
    rowData := rowData collect:[:row | row copyWithoutIndex:index].
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1072
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1073
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1074
     self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1075
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1076
        removeColumn:1;
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1077
        inspect.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1078
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1079
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1080
    "Created: / 06-01-2019 / 13:05:41 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1081
    "Modified (comment): / 09-01-2019 / 12:13:50 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1082
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1083
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1084
removeColumnNamed:name
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1085
    "destructively remove a column"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1086
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1087
    self removeColumn:(self indexOfColumnNamed:name)
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1088
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1089
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1090
     self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1091
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1092
        removeColumnNamed:'STATIONS_ID';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1093
        removeColumnNamed:'QN_3';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1094
        removeColumnNamed:'FX';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1095
        removeColumnNamed:'FM';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1096
        removeColumnNamed:'RSK';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1097
        removeColumnNamed:'RSKF';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1098
        removeColumnNamed:'SDK';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1099
        removeColumnNamed:'SHK_TAG';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1100
        removeColumnNamed:'NM';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1101
        removeColumnNamed:'VPM';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1102
        removeColumnNamed:'PM';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1103
        removeColumnNamed:'TMK';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1104
        removeColumnNamed:'UPM';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1105
        removeColumnNamed:'eor';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1106
        inspect.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1107
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1108
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1109
    "/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1110
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1111
    "Created: / 06-01-2019 / 13:06:50 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1112
    "Modified (comment): / 09-01-2019 / 12:13:53 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1113
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1114
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1115
withColumns:indexCollection
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1116
    "return a new TableData instance, containing only the given columns"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1117
    
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1118
    |remainingNames|
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1119
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1120
    remainingNames := indexCollection collect:[:colIdx | columnNames at:colIdx] as:Array.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1121
    ^ self class
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1122
        rows:(rowData collect:[:row | 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1123
                indexCollection collect:[:colIdx | row at:colIdx] as:Array
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1124
                ])
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1125
        columnNames:remainingNames.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1126
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1127
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1128
     (self fromFile:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1129
        withColumns:#(1 2 3).
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1130
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1131
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1132
    "Created: / 06-01-2019 / 14:35:11 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1133
    "Modified (comment): / 09-01-2019 / 12:13:57 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1134
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1135
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1136
withColumnsNamed:nameCollection
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1137
    "return a new TableData instance, containing only the given columns"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1138
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1139
    ^ self withColumns:(nameCollection collect:[:nm |self indexOfColumnNamed:nm])
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1140
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1141
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1142
     (self fromFile:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1143
        withColumnsNamed:#('MESS_DATUM' 'TXK').
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1144
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1145
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1146
    "Created: / 06-01-2019 / 14:36:16 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1147
    "Modified (comment): / 09-01-2019 / 12:13:45 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1148
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1149
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1150
withoutColumn:index
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1151
    "return a new TableData instance, without the given columns"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1152
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1153
    ^ self class
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1154
        rows:(rowData collect:[:row | row copyWithoutIndex:index])
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1155
        columnNames:(columnNames copyWithoutIndex:index).
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1156
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1157
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1158
     self new 
4789
4daaaab89349 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4781
diff changeset
  1159
        readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1160
        withoutColumn:1.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1161
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1162
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1163
    "Created: / 06-01-2019 / 13:27:11 / Claus Gittinger"
4789
4daaaab89349 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4781
diff changeset
  1164
    "Modified (comment): / 10-01-2019 / 16:25:56 / Claus Gittinger"
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1165
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1166
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1167
withoutColumns:indexCollection
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1168
    "return a new TableData instance, without the given columns"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1169
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1170
    |remainingColIndices remainingNames|
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1171
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1172
    remainingColIndices := (1 to:columnNames size) asNewOrderedCollection removeAll:indexCollection; yourself.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1173
    remainingNames := remainingColIndices collect:[:colIdx | columnNames at:colIdx] as:Array.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1174
    ^ self class
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1175
        rows:(rowData collect:[:row | 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1176
                remainingColIndices collect:[:colIdx | row at:colIdx] as:Array
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1177
                ])
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1178
        columnNames:remainingNames.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1179
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1180
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1181
     (self fromFile:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1182
        withoutColumns:#(1 2 3).
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1183
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1184
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1185
    "Created: / 06-01-2019 / 14:32:08 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1186
    "Modified (comment): / 09-01-2019 / 12:14:29 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1187
! !
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1188
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1189
!TableData methodsFor:'reading'!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1190
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1191
readCSV:filename
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1192
    ^ self readCSV:filename separator:$; skip:0
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1193
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1194
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1195
     self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1196
        readCSV:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1197
        inspect.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1198
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1199
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1200
    "
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1201
     self new 
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1202
        readCSV:'/Users/exept/Downloads/masie_4km_allyears_extent_sqkm.csv';
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1203
        inspect.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1204
    "
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1205
    "Created: / 09-01-2019 / 12:07:27 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1206
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1207
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1208
readCSV:filename separator:separatorCharacter
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1209
    ^ self readCSV:filename separator:separatorCharacter skip:0
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1210
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1211
    "
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1212
     self new 
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1213
        readCSV:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1214
        inspect.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1215
    "
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1216
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1217
    "Created: / 09-01-2019 / 12:11:11 / Claus Gittinger"
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1218
!
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1219
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1220
readCSV:filename separator:separatorCharacter skip:numLinesToSkip
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1221
    |headLine numCols dataLine ls word row rows|
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1222
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1223
    filename asFilename readingFileDo:[:s |
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1224
        numLinesToSkip timesRepeat:[s nextLine].
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1225
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1226
        rows := OrderedCollection new.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1227
        headLine := s nextLine.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1228
        numCols := (headLine occurrencesOf:separatorCharacter)+1.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1229
        columnNames := (headLine splitBy:separatorCharacter) collect:#withoutSeparators.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1230
        [s atEnd] whileFalse:[
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1231
            dataLine := s nextLine.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1232
            ls := dataLine readStream.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1233
            row := OrderedCollection new:numCols.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1234
            [ls atEnd] whileFalse:[
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1235
                ls skipSeparators.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1236
                word := (ls upTo:separatorCharacter) withoutSeparators.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1237
                row add:word.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1238
            ].
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1239
            rows add:(row asArray).
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1240
        ].
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1241
    ].
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1242
    rowData := rows.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1243
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1244
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1245
     self new 
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1246
        readCSV:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1247
        inspect.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1248
    "
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1249
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1250
    "Created: / 09-01-2019 / 12:11:11 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1251
!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1252
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1253
readCSV:filename skip:numLinesToSkip
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1254
    ^ self readCSV:filename separator:$; skip:numLinesToSkip
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1255
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1256
    "
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1257
     self new 
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1258
        readCSV:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1259
        inspect.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1260
    "
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1261
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1262
    "
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1263
     self new 
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1264
        readCSV:'/Users/exept/Downloads/masie_4km_allyears_extent_sqkm.csv' skip:1;
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1265
        inspect.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1266
    "
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1267
    "Created: / 09-01-2019 / 12:07:27 / Claus Gittinger"
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1268
!
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1269
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1270
readDemoCSV
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1271
    self readCSV:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt'.
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1272
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1273
    "Created: / 09-01-2019 / 12:07:52 / Claus Gittinger"
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1274
! !
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1275
5232
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1276
!TableData methodsFor:'writing'!
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1277
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1278
writeCSVToStream:aStream
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1279
    "save myself as CSV onto a stream"
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1280
    
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1281
    columnNames 
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1282
        do:[:nm | 
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1283
            (nm includes:$;) ifTrue:[
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1284
                aStream nextPut:$"; nextPutAll:nm; nextPut:$".
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1285
            ] ifFalse:[
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1286
                aStream nextPutAll:nm
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1287
            ]]
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1288
        separatedBy:[aStream nextPut:$;].
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1289
    aStream cr.        
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1290
    rowData do:[:row |
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1291
        row
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1292
            do:[:col | 
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1293
                |s|
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1294
                s := col printString.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1295
                (s includes:$;) ifTrue:[
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1296
                    aStream nextPut:$"; nextPutAll:s; nextPut:$".
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1297
                ] ifFalse:[
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1298
                    aStream nextPutAll:s
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1299
                ]
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1300
            ]
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1301
            separatedBy:[aStream nextPut:$;].
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1302
        aStream cr.        
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1303
    ].
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1304
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1305
    "
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1306
     |data tmax|
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1307
     
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1308
     data := self fromFile:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt'.
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1309
     tmax := data withColumnsNamed:#('MESS_DATUM' 'TXK' 'TNK').
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1310
     String streamContents:[:s | tmax writeCSVToStream:s]
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1311
    "
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1312
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1313
    "Created: / 09-01-2019 / 17:48:25 / Claus Gittinger"
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1314
! !
a99483a7340f #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4973
diff changeset
  1315
4781
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1316
!TableData class methodsFor:'documentation'!
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1317
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1318
version_CVS
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1319
    ^ '$Header$'
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1320
! !
a4d11bd443dc initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1321