Check-in [46916d9772]

Not logged in
Tcl 2015 Conference, Manassas/VA, US, Oct 19-23
Send your abstracts to tclconference@googlegroups.com by Aug 24.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fixes to city validation, added introspection and testing to same.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | active-on-core
Files: files | file ages | folders
SHA1:46916d9772a0bf528867b3e46581b7f1f9fa2bec
User & Date: aku 2017-09-25 17:51:02
Context
2017-09-25
17:51
Expose the test commands for city and location validation check-in: 32c2050e25 user: aku tags: active-on-core
17:51
Fixes to city validation, added introspection and testing to same. check-in: 46916d9772 user: aku tags: active-on-core
17:50
Added introspection/testing for location validation check-in: ac0207111b user: aku tags: active-on-core
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to lib/city.tcl.

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

48
49
50
51
52
53










54
55
56
57
58
59
60
..
66
67
68
69
70
71
72
















73
74
75
76
77
78
79
...
113
114
115
116
117
118
119













120
121
122
123
124
125
126
...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# # ## ### ##### ######## ############# ######################

namespace eval ::cm {
    namespace export city
    namespace ensemble create
}
namespace eval ::cm::city {
    namespace export cmd_create cmd_list \
	select label get known-validation
    namespace ensemble create

    namespace import ::cmdr::color
    namespace import ::cmdr::ask
    namespace import ::cm::util
    namespace import ::cm::db

    namespace import ::cmdr::table::general ; rename general table

}

# # ## ### ##### ######## ############# ######################

debug level  cm/city
debug prefix cm/city {[debug caller] | }











# # ## ### ##### ######## ############# ######################

proc ::cm::city::cmd_list {config} {
    debug.cm/city {}
    Setup
    db show-location
................................................................................
	    ORDER BY name, state, nation
	} {
	    $t add $name $state $nation
	}
    }] show
    return
}

















proc ::cm::city::cmd_create {config} {
    debug.cm/city {}
    Setup
    db show-location

    # try to insert, report failure as user error
................................................................................
	SELECT name, state, nation
	FROM  city
	WHERE id = :id
    }] name state nation

    return [label $name $state $nation]
}














proc ::cm::city::label {name state nation} {
    debug.cm/city {}

    set label $name
    if {$state ne {}} {append label ", $state"}
    append label ", $nation"
................................................................................
proc ::cm::city::known-validation {} {
    set map {}

    db do eval {
	SELECT id, name AS city, state, nation
	FROM   city
    } {
	dict lappend map $id [label $city $state $nation]

	if {$state ne {}} {
	    set label "$city $state $nation"
	} else {
	    set label "$city $nation"
	}
	set initials  [util initials $label]
	set llabel    [string tolower $label]
	set linitials [string tolower $initials]

	dict lappend map $id $label  "$initials $label"
	dict lappend map $id $llabel "$linitials $llabel"
    }

    # Rekey by names, then extend with key permutations which do not
    # clash, lastly drop all keys with multiple outcomes.
    set map   [util dict-invert         $map]
    # Long names for hotels, longer with location ... Too slow at the moment.







|









>






>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>







 







|










|







31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
..
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
...
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
...
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# # ## ### ##### ######## ############# ######################

namespace eval ::cm {
    namespace export city
    namespace ensemble create
}
namespace eval ::cm::city {
    namespace export cmd_create cmd_list cmd_show test-known \
	select label get known-validation
    namespace ensemble create

    namespace import ::cmdr::color
    namespace import ::cmdr::ask
    namespace import ::cm::util
    namespace import ::cm::db

    namespace import ::cmdr::table::general ; rename general table
    namespace import ::cmdr::table::dict    ; rename dict    table/d
}

# # ## ### ##### ######## ############# ######################

debug level  cm/city
debug prefix cm/city {[debug caller] | }

# # ## ### ##### ######## ############# ######################

proc ::cm::city::test-known {config} {
    debug.cm/city {}
    Setup
    db show-location
    util pdict [known-validation]
    return
}

# # ## ### ##### ######## ############# ######################

proc ::cm::city::cmd_list {config} {
    debug.cm/city {}
    Setup
    db show-location
................................................................................
	    ORDER BY name, state, nation
	} {
	    $t add $name $state $nation
	}
    }] show
    return
}

proc ::cm::city::cmd_show {config} {
    debug.cm/city {}
    Setup
    db show-location

    set city [$config @city]
    lassign [details $city] name state nation
   
    [table/d t {
	$t add Name   $name
	$t add State  $state
	$t add Nation $nation
    }] show
    return
}

proc ::cm::city::cmd_create {config} {
    debug.cm/city {}
    Setup
    db show-location

    # try to insert, report failure as user error
................................................................................
	SELECT name, state, nation
	FROM  city
	WHERE id = :id
    }] name state nation

    return [label $name $state $nation]
}

proc ::cm::city::details {id} {
    debug.cm/city {}
    Setup

    lassign [db do eval {
	SELECT name, state, nation
	FROM  city
	WHERE id = :id
    }] name state nation

    return [list $name $state $nation]
}

proc ::cm::city::label {name state nation} {
    debug.cm/city {}

    set label $name
    if {$state ne {}} {append label ", $state"}
    append label ", $nation"
................................................................................
proc ::cm::city::known-validation {} {
    set map {}

    db do eval {
	SELECT id, name AS city, state, nation
	FROM   city
    } {
	dict lappend map $id [string tolower [label $city $state $nation]]

	if {$state ne {}} {
	    set label "$city $state $nation"
	} else {
	    set label "$city $nation"
	}
	set initials  [util initials $label]
	set llabel    [string tolower $label]
	set linitials [string tolower $initials]

	#dict lappend map $id $label  "$initials $label"
	dict lappend map $id $llabel "$linitials $llabel"
    }

    # Rekey by names, then extend with key permutations which do not
    # clash, lastly drop all keys with multiple outcomes.
    set map   [util dict-invert         $map]
    # Long names for hotels, longer with location ... Too slow at the moment.