source: tol/tolbase/lib/toltk/drawarima.tcl @ b47c991

1941-docker-image-to-testdevel
Last change on this file since b47c991 was 6d7779d, checked in by Jorge Pérez <josp.jorge@…>, 18 years ago

initial import

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@1 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100644
File size: 9.0 KB
Line 
1#/////////////////////////////////////////////////////////////////////////////
2# FILE    : drawarima.tcl
3# PURPOSE : This file contains a namespace called drawArima with its
4#           functions. It's for creating a form that allows to define an
5#           ARIMA model and plot its Auto Correlation Function and its Partial
6#           Auto Correlation Function.
7#/////////////////////////////////////////////////////////////////////////////
8package require barima
9package require bentrydate
10
11
12#/////////////////////////////////////////////////////////////////////////////
13namespace eval drawArima {
14#
15# PURPOSE: The purpose of this namespace is organize code and functions.
16#          It also stotres a special namespace is created for each instance
17#          of drawArima.
18# VARIABLES:
19#   data -> array with information functions search
20#     x -> p
21#   widget -> contains the widget
22#   sensitive -> has a value 1 if the user has selected case sensitive search
23#
24#/////////////////////////////////////////////////////////////////////////////
25  variable data
26  variable widget
27}
28
29
30#/////////////////////////////////////////////////////////////////////////////
31proc ::drawArima::Show {} {
32#
33# PURPOSE: Shows the form to show ACFs and PACFs of an ARIMA Model
34#
35#/////////////////////////////////////////////////////////////////////////////
36  variable widget   
37  if { [info exist widget(document)] && [winfo exists $widget(document)] } {
38    if { [$widget(document) cget -state] eq "minimized" } {
39      $widget(document) restore
40    }
41    $widget(document) raise
42  } else {
43    Create
44  }
45}
46
47
48#/////////////////////////////////////////////////////////////////////////////
49proc ::drawArima::Create {} {
50#
51# PURPOSE: Creates the draw ARIMA dialog
52#
53# PARAMETERS:
54#   path: path of dialgo's parent
55#
56#/////////////////////////////////////////////////////////////////////////////
57  global toltk_options
58  variable data
59  variable widget
60   
61  # Create the widget
62  set widget(document) [::project::CreateForm \
63    -iniconfig FunctionSearch \
64    -title [mc "Draw ACF and PACF of ARIMA Models"] \
65    -resizable 0 -width 680 -height 230 -helpkey "Tb4HanAriGra"]
66  set f0 [$widget(document) getframe]
67 
68  set tfm [TitleFrame $f0.tfm -text [mc "Parameters of the graph"]]
69  set f [$tfm getframe]
70 
71  set widget(ba) [barima $f.ba -parent $widget(document) -coderequired 1 \
72                               -codeeditable 1 -timesetrequired 1]
73  set widget(tfs) [TitleFrame $f.tfs -text [mc "Date Selector"] ]
74  set widget(frs) [$widget(tfs) getframe] 
75  set widget(ledf) [Label $widget(frs).ledf -text [mc "Date first"]]
76  set widget(lrf)  [Label $widget(frs).lrf -image [::Bitmap::get brequired] \
77                                       -helptext [mc "Date first required"] ]
78  set ::drawArima::data(bedf) ""
79  set widget(bedf) [bentrydate $widget(frs).bedf \
80                                         -bdate [::drawArima::TxtDef first] ]
81  set widget(ledl) [Label $widget(frs).ledl -text [mc "Date last"]]
82  set widget(lrl)  [Label $widget(frs).lrl -image [::Bitmap::get brequired] \
83                         -helptext [mc "Date last required"] ]
84  set ::drawArima::data(bedl) ""
85  set widget(bedl) [bentrydate $widget(frs).bedl \
86                         -bdate [::drawArima::TxtDef last] ]
87  set datetmp [::drawArima::TxtDef last]
88  $widget(bedl) Set [lindex $datetmp 0] [lindex $datetmp 1] \
89                    [lindex $datetmp 2]
90  set widget(bbox) \
91          [ButtonBox $f.bbox -orient horizontal -spacing 10 -padx 0 -pady 0 \
92          -homogeneous false]
93
94  $widget(bbox) add -relief link \
95          -helptext [mc "Draw ACF and PACF of ARIMA Model"] \
96          -text [mc "Draw"] \
97          -image [::Bitmap::get graphbar] -compound left -padx 5 -pady 1 \
98          -command [list ::drawArima::Draw ]
99  $widget(bbox) add -relief link -helptext [mc "Exit"] -text [mc "Exit"]\
100          -image [::Bitmap::get exit] -compound left -padx 5 -pady 1 \
101          -command [list ::drawArima::Destroy]
102
103  pack  $tfm          -side top -fill both -expand yes
104  pack  $widget(bbox) -side bottom -fill both -expand yes
105  pack  $widget(ba)   -side left   -fill both -expand yes
106  pack  $widget(tfs)  -side top    -fill both -expand yes
107
108  grid $widget(ledf) -             -sticky nw
109  grid $widget(lrf)  $widget(bedf) -sticky nw 
110  grid $widget(ledl) -             -sticky nw
111  grid $widget(lrl)  $widget(bedl) -sticky nw
112
113  grid columnconfigure $f0 0 -weight 1
114  grid rowconfigure    $f0 0 -weight 1
115  grid columnconfigure $f  0 -weight 1
116  grid rowconfigure    $f  0 -weight 1
117 
118  grid columnconfigure $widget(frs) 0 -weight 0
119  grid columnconfigure $widget(frs) 1 -weight 1
120}
121
122
123#/////////////////////////////////////////////////////////////////////////////
124proc ::drawArima::Destroy {} {
125#
126# PURPOSE: Hides draw ARIMA document.
127#
128#/////////////////////////////////////////////////////////////////////////////
129  variable widget
130  variable data
131  array unset data
132  destroy $widget(document)
133}
134
135#/////////////////////////////////////////////////////////////////////////////
136proc ::drawArima::Draw {} {
137#
138# PURPOSE: It verifies if all the required fields are filled and draws.
139#
140# RETURN: 1 if the graph has been generated, 0 otherwise
141#////////////////////////////////////////////////////////////////////////////
142  variable widget
143  variable data
144  set ret 0
145  set val [::drawArima::Validate]
146  switch -- $val {
147    1 {
148      # all the required fields are filled
149      ::drawArima::DrawCFs [$widget(ba) cget -value] \
150                           [$widget(bedf) cget -btext] \
151                           [$widget(bedl) cget -btext] \
152                           [$widget(ba) get "TimeSet"]
153      set ret 1
154    }
155    "-1" {
156      # error: all the required fields are not filled
157      ShowMessage E [mc "All the required parameters must be filled"] \
158                $widget(document)
159    }
160    "-2" {
161      # error: the initial date is greater than the end date
162      ShowMessage E [mc "The date last must be higher than the date fist"] \
163                $widget(document)
164    }
165    "-3" {
166      # error: the dates do not have the correct format
167      ShowMessage E [mc "Dates do not have the correct format"] \
168                $widget(document)
169    }
170  }
171  return $ret
172}
173
174#/////////////////////////////////////////////////////////////////////////////
175proc ::drawArima::Validate {} {
176#
177# PURPOSE: Verifies the fields are filled correctly
178#
179# RETURN: 0 if all its ok,
180#        -1 if all the required fields are not filled
181#        -2 if the initial date is greater than the end date
182#        -3 the dates do not have the correct format
183#
184#/////////////////////////////////////////////////////////////////////////////
185  variable widget
186  variable data
187  set tarima  [$widget(ba) cget -value]
188  set tfirst  [$widget(bedf) cget -btext]
189  set tlast   [$widget(bedl) cget -btext]
190  set timeset [$widget(ba) get "TimeSet"]
191  set ok 0
192  if { !($timeset eq "") } { ;# timeset filled
193    if { !($tarima eq "") } { ;# code filled
194      if { !($tfirst eq "") } { ;# date first filled
195        if { !($tlast eq "") } { ;# date last filled
196          set ok 1
197        } else {
198          set ok -1
199        }
200      } else {
201        set ok -1
202      }
203    } else {
204      set ok -1
205    }
206  } else {
207    set ok -1
208  }
209  if { ($ok eq 1) && ( $tfirst > $tlast ) } {
210    # date first is higher than date last
211    set ok -2
212  }
213  if { ($ok eq 1) && ( ( [CheckDateTime $tfirst] eq 0 ) ||
214                       ( [CheckDateTime $tlast] eq 0 ) ) } {
215    # dates aren't the correct format
216    set ok -3
217  }
218  return $ok
219}
220
221#/////////////////////////////////////////////////////////////////////////////
222proc ::drawArima::DrawCFs {arima tfirst tlast timeset} {
223#
224# PURPOSE: Draws the graph of ACFs and PACFs of ARIMA Model
225#
226# PARAMETERS:
227#   arima -> string that defines the ARIMA model
228#   tfirst -> text of first date
229#   tlast -> text of last date
230#   timeset -> text of timeset
231#/////////////////////////////////////////////////////////////////////////////
232  set dfirst "y[string range $tfirst 0 3]m[string range $tfirst 4 5]d[string range $tfirst 6 7]"
233  set dlast  "y[string range $tlast 0 3]m[string range $tlast 4 5]d[string range $tlast 6 7]"
234  set graphTitle1 [mc "Graph of ACFs and PACFs of ARIMA Model"]
235  set graphTitle "${graphTitle1}: $arima" 
236  set sentence \
237    "Anything ARIMADrawACFs( Serie (ARIMAGetGaussian(Text \"$arima\", Date $dfirst, Date $dlast, TimeSet $timeset)), Text (\"$graphTitle\"));"
238  ::tol::console eval $sentence
239}
240
241
242#/////////////////////////////////////////////////////////////////////////////
243proc ::drawArima::TxtDef {args} {
244#
245# PURPOSE: Returns the correct value of date defined in Tol DefFirst or
246#          DefLast to give it to bentrydate
247#
248#/////////////////////////////////////////////////////////////////////////////ç
249  set res ""
250  if {$args eq "first"} {
251    set res [TclGetVar Date DefFirst CONTENT]
252  }
253  if {$args eq "last"} {
254    set res [TclGetVar Date DefLast CONTENT]
255  }
256  set tmp $res
257  if {!($res eq "")} {
258    set res [list [list [string range $tmp 1 4]] \
259                  [list [string range $tmp 6 7]] \
260                  [list [string range $tmp 9 10]]]
261  }
262  return $res
263}
264 
Note: See TracBrowser for help on using the repository browser.