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