dwelldelta-mcp 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +10 -4
- package/README.md +60 -15
- package/area-rents-tool.mjs +164 -32
- package/contribute-tool.mjs +46 -8
- package/cover-tool.mjs +48 -13
- package/feed-text.mjs +214 -0
- package/output-schemas.mjs +4 -1
- package/package.json +3 -2
- package/pages.mjs +27 -4
- package/place-tool.mjs +205 -29
- package/register-tools.mjs +66 -41
- package/sale-prices-tool.mjs +10 -4
- package/server.mjs +11 -6
- package/tools.mjs +40 -14
- package/vendor/contribute.mjs +49 -2
- package/vendor/contribution-places.json +2178 -0
- package/vendor/indicators.json +4 -4
- package/vendor/tas-rents-interim.json +4 -4
- package/vendor/tas-rents.json +1109 -0
- package/vic-rents-tool.mjs +9 -4
package/LICENSE
CHANGED
|
@@ -20,13 +20,16 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
|
22
22
|
|
|
23
|
-
The data files in vendor/ (rents-index.json, indicators.json, nsw-suburbs.json,
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
The data files in vendor/ (rents-index.json, indicators.json, nsw-suburbs.json,
|
|
24
|
+
contribution-places.json, vic-rents.json, nsw-rents.json, qld-rents.json, wa-rents.json,
|
|
25
|
+
sa-rents.json, tas-rents.json, nsw-sales.json, nz-rents.json, act-rents-interim.json,
|
|
26
|
+
nt-rents-interim.json, tas-rents-interim.json) are
|
|
26
27
|
not covered by this licence. Each figure keeps its source's own licence and
|
|
27
28
|
attribution, which the data files and every answer state (for example, ABS data:
|
|
28
29
|
CC BY 4.0, "Based on Australian Bureau of Statistics data"; the NSW suburb list:
|
|
29
|
-
CC BY 3.0 AU, NSW Spatial Services;
|
|
30
|
+
CC BY 3.0 AU, NSW Spatial Services; the contribution place list: the place names
|
|
31
|
+
of the Victorian, Queensland, WA and SA rents feeds, each under its licence here;
|
|
32
|
+
Victorian rents: CC BY 4.0, Homes Victoria;
|
|
30
33
|
NSW rents: CC BY 4.0, State of New South Wales (Department of Communities and
|
|
31
34
|
Justice); Queensland rents: CC BY 4.0, The State of Queensland (Residential
|
|
32
35
|
Tenancies Authority); WA rents: based on WA Rental Bonds Data, CC BY 4.0,
|
|
@@ -34,6 +37,9 @@ Government of Western Australia, with medians calculated by DwellDelta;
|
|
|
34
37
|
SA rents: South Australian Housing Trust, Government of South Australia,
|
|
35
38
|
Private Rent Report, whose own page states no licence - the national
|
|
36
39
|
catalogues list CC BY 4.0 and CC BY 3.0 AU;
|
|
40
|
+
Tasmanian rents: based on Department of Justice (Tasmania), Rental Bond and
|
|
41
|
+
Rental Data, CC BY 4.0 as data.gov.au lists it, with medians calculated by
|
|
42
|
+
DwellDelta;
|
|
37
43
|
NSW sale prices: CC BY 4.0, State of New South Wales (Department of
|
|
38
44
|
Communities and Justice); New Zealand rents: CC BY 3.0 NZ, the Ministry of
|
|
39
45
|
Business, Innovation and Employment, Tenancy Services rental bond data; ACT,
|
package/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# dwelldelta-mcp - is an Australian rent fair?
|
|
2
2
|
|
|
3
3
|
An MCP server that lets an AI assistant check a weekly rent against the ABS rents index, look up median rents
|
|
4
|
-
by area in
|
|
4
|
+
by area in six states and New Zealand (with interim ABS cover for the ACT, the Northern Territory and the Tasmanian
|
|
5
|
+
postcodes its bond medians give no figure for) and
|
|
5
6
|
NSW median sale prices, and quote sourced Australian property and lending indicators. From
|
|
6
7
|
[DwellDelta](https://dwelldelta.com.au/), a service of Xcelerent Pty Ltd, built on public data.
|
|
7
8
|
|
|
@@ -10,10 +11,10 @@ Seven read-only tools, and one that adds the user's own rent when they ask:
|
|
|
10
11
|
| Tool | What it answers |
|
|
11
12
|
|---|---|
|
|
12
13
|
| `rent_check` | a weekly rent, and any proposed new rent, against the ABS rents index for the capital city since the lease began (the same arithmetic as the rent check at tools.dwelldelta.com.au); or, given a `place` instead of a lease start, against that place's median of new bonds or leases, and its quartiles where published (from 0.12.0) |
|
|
13
|
-
| `property_rents` | the rents of a place asked with no state - a suburb, locality or postcode - answered from the state that holds it (NSW, Victoria, Queensland, WA or
|
|
14
|
+
| `property_rents` | the rents of a place asked with no state - a suburb, locality or postcode - answered from the state that holds it (NSW, Victoria, Queensland, WA, SA or, from 0.16.0, Tasmania); an NSW or Tasmanian suburb is answered for its postcode, and a name held in more than one state is listed, not chosen (from 0.12.0). From 0.14.0 also a New Zealand council or region (MBIE's bonds for one month, in NZ$, provisional) and an ACT, NT or Tasmanian postcode (interim ABS cover: the rent paid at the 2021 Census, the capital's rents index, sale prices - not new-bond medians; for Tasmania from 0.16.0 only a postcode its bond medians give no figure for) |
|
|
14
15
|
| `market_indicators` | the latest RBA cash rate, unemployment, wage growth, rents for all eight capitals, NSW lending, lending standards and arrears, approvals and completions - each with period, source, licence and limits; filter by `geography` |
|
|
15
16
|
| `vic_rents` | Victorian rents by suburb group from Homes Victoria's Rental Report: the median weekly rent of new leases, the lease count and the change on a year before, for 146 suburb groups and 13 regions; filter by `suburb_group` or `region` (from 0.5.0) |
|
|
16
|
-
| `area_rents` | median weekly rent of new bonds, all dwellings together, with the bond count and the change on a year before, for one state per call: NSW by postcode or council (NSW Department of Communities and Justice), Queensland by suburb or council (Residential Tenancies Authority), WA by locality (calculated by DwellDelta from the Government of Western Australia's bond records), SA by suburb (SA Housing Trust, Private Rent Report; its publisher's page states no licence, and the national catalogues list CC BY); each file states CC BY 4.0 (from 0.6.0; SA from 0.11.0) |
|
|
17
|
+
| `area_rents` | median weekly rent of new bonds, all dwellings together, with the bond count and the change on a year before, for one state per call: NSW by postcode or council (NSW Department of Communities and Justice), Queensland by suburb or council (Residential Tenancies Authority), WA by locality (calculated by DwellDelta from the Government of Western Australia's bond records), SA by suburb (SA Housing Trust, Private Rent Report; its publisher's page states no licence, and the national catalogues list CC BY), Tasmania by postcode (calculated by DwellDelta from the Department of Justice's bond records, private housing, one month at a time; CC BY 4.0 as data.gov.au lists it); each file states CC BY 4.0 (from 0.6.0; SA from 0.11.0; Tasmania from 0.16.0) |
|
|
17
18
|
| `nsw_sale_prices` | NSW median sale prices by postcode or council from the NSW Department of Communities and Justice's Rent and Sales Report (CC BY 4.0): the median, the quartiles, the number of sales and the change on a year before, each for all dwellings, houses (non-strata) and units and town houses (strata). Medians of homes sold - never what any one home sold for; a line set by a few very large sales or by many sales at one identical price is marked UNUSUAL (from 0.7.0), and is not a going price |
|
|
18
19
|
| `data_sources` | the sources, their licences, and what DwellDelta cannot answer |
|
|
19
20
|
| `contribute_rent` | adds the user's own rent, anonymously, to DwellDelta's suburb benchmarks - only when the user asks, and only after they have read and agreed to the consent wording (from 0.5.0) |
|
|
@@ -25,13 +26,21 @@ files in all from 0.14.0, the same for everyone; nothing about you or your quest
|
|
|
25
26
|
copies it ships with (all but the two rents by dwelling type files). Set `DWELLDELTA_OFFLINE=1` and none of those files is fetched; adding a rent with `contribute_rent` still sends it, as you asked. Nothing it says is a
|
|
26
27
|
forecast, a valuation or advice.
|
|
27
28
|
|
|
29
|
+
A fetched file's text must keep a few rules of form before it answers (from 0.16.0): no control, bidi or
|
|
30
|
+
zero-width character and no string over 4,000 characters; a place's name only letters, digits, spaces and a few
|
|
31
|
+
marks of punctuation, at most 80 characters; a band, a period and a postcode each in its own spelling; and every field
|
|
32
|
+
name in snake case. A row or line that breaks one is left out and the rest of the file answers; anything else that
|
|
33
|
+
breaks one, and the file is not used - the copy the package ships answers. The server says so in one line on stderr,
|
|
34
|
+
and each answer says so too: `newer_copy_refused` (with `newer_copy_refused_class`) and `published_rows_left_out`.
|
|
35
|
+
|
|
28
36
|
## Adding a rent (from 0.5.0)
|
|
29
37
|
|
|
30
38
|
`contribute_rent` is the one tool that can send anything, and it takes two calls. The first stores and sends
|
|
31
39
|
nothing: it returns the consent wording, the [Contributor Terms](https://tools.dwelldelta.com.au/terms/) and
|
|
32
40
|
[Privacy Notice](https://tools.dwelldelta.com.au/privacy/), and a token. Only when the assistant has shown you
|
|
33
41
|
that wording and you have said yes does it call again, with the token. What is then stored, in AWS Sydney, is the
|
|
34
|
-
suburb
|
|
42
|
+
suburb (in Western Australia the locality, in Victoria the Homes Victoria suburb group), home type, bedrooms, rent,
|
|
43
|
+
lease month and lease kind, and whether it is a rent you pay or the rent of a
|
|
35
44
|
property you own - never an address, name or email. You get a deletion code; email it to lingtao@xcelerent.com
|
|
36
45
|
and the record is deleted. Only your own rent may be added: an assistant must not add a figure it read on a
|
|
37
46
|
website or a listing.
|
|
@@ -81,15 +90,26 @@ median rent of new leases in postcode 2148?" or "What is NSW unemployment doing?
|
|
|
81
90
|
|
|
82
91
|
## Rents by area (from 0.6.0)
|
|
83
92
|
|
|
84
|
-
`area_rents` answers for one state at a time, because the
|
|
85
|
-
medians are DwellDelta's own calculation from the
|
|
93
|
+
`area_rents` answers for one state at a time, because the five publishers measure in their own ways and the WA
|
|
94
|
+
and Tasmanian medians are DwellDelta's own calculation from the Governments' one-record-per-bond data. They must not be added
|
|
86
95
|
or ranked as one series. Every answer carries that state's quarter, its source line, what DwellDelta selected or
|
|
87
96
|
calculated, and its limits. These are medians of new bonds, all dwellings together - not advertised rents, not
|
|
88
97
|
what sitting tenants pay, and not the rent of a home of a given size. Where a publisher reports nothing for a
|
|
89
98
|
small area the answer says so; it never shows a zero. The feeds are public at
|
|
90
|
-
https://tools.dwelldelta.com.au/market/nsw-rents.json, `qld-rents.json`, `wa-rents.json
|
|
91
|
-
server reads them at start the way it reads the indicators, and `DWELLDELTA_STATE_RENTS_DIR`
|
|
92
|
-
copies. Victoria, measured differently again, stays in `vic_rents`.
|
|
99
|
+
https://tools.dwelldelta.com.au/market/nsw-rents.json, `qld-rents.json`, `wa-rents.json`, `sa-rents.json` and
|
|
100
|
+
`tas-rents.json`; the server reads them at start the way it reads the indicators, and `DWELLDELTA_STATE_RENTS_DIR`
|
|
101
|
+
points it at a folder of copies. Victoria, measured differently again, stays in `vic_rents`.
|
|
102
|
+
|
|
103
|
+
Tasmania's file (from 0.16.0) is by postcode and is a MONTH's, not a quarter's: a Tasmanian answer's `quarter` is
|
|
104
|
+
null, and its month is in `month` ("2026-08") and `month_words` ("August 2026"), fields of its own; `data_as_of` is
|
|
105
|
+
the month, and the answer is overdue four months after it. The medians are DwellDelta's, of the private-housing
|
|
106
|
+
bonds lodged in the month (community housing left out); a postcode needs 10 bonds for a median, and one on fewer than
|
|
107
|
+
30 is a small sample. One month is held, so no change on a year is given. `area` takes a postcode or a suburb name
|
|
108
|
+
the month's bonds were lodged under (each postcode's line lists them), answered for its whole postcode with a note
|
|
109
|
+
saying so. The state alone also gives the state's medians by bedrooms and by dwelling type (`state_breakdown`); no
|
|
110
|
+
postcode has them, so `dwelling_type` and `bedrooms` are refused for a postcode. The licence is CC BY 4.0 as
|
|
111
|
+
data.gov.au lists the dataset, not read at source: `cite_as` says "CC BY 4.0 as data.gov.au lists it", and
|
|
112
|
+
`source_url` is data.gov.au's listing.
|
|
93
113
|
|
|
94
114
|
South Australia's file holds one quarter today, so its `compared_with`, year-ago medians and changes are null and no
|
|
95
115
|
answer names a year it is compared with. Its counts of bonds are rounded to the nearest 5 (the SA Housing Trust's note says so of its totals;
|
|
@@ -126,19 +146,25 @@ It is listed in the MCP registry as `au.com.dwelldelta/dwelldelta`.
|
|
|
126
146
|
bonds lodged in an Australian quarter, in Australian dollars. Nothing is compared across states or countries.
|
|
127
147
|
|
|
128
148
|
- **New Zealand**, by council (territorial authority) or region, as MBIE names them ("Wellington City", "Auckland",
|
|
129
|
-
"Canterbury Region"; "Wellington, NZ" lists the city and the region
|
|
149
|
+
"Canterbury Region"; "Wellington, NZ" lists the city and the region, and
|
|
150
|
+
"Wellington" alone, an NSW suburb too, lists all three): MBIE Tenancy Services' median weekly rent of
|
|
130
151
|
the bonds for private tenancies that began in the latest month, with its geometric mean, quartiles and bond count,
|
|
131
152
|
CC BY 3.0 NZ. Every amount is in New Zealand dollars, written NZ$, in fields ending `_nzd`; MBIE calls the data
|
|
132
153
|
provisional, so no change on a year is given. A figure on fewer than 30 bonds is a small sample; MBIE gives none
|
|
133
154
|
below 5. The answer carries `country: "NZ"`, `currency: "NZD"`, `provisional: true`, `nz_place`, and the place's
|
|
134
155
|
page at tools.dwelldelta.com.au/area/nz/.
|
|
135
|
-
- **The ACT, the Northern Territory and Tasmania**, by postcode, or the state or its capital alone
|
|
156
|
+
- **The ACT, the Northern Territory and Tasmania**, by postcode, or the state or its capital alone (from 0.16.0, for
|
|
157
|
+
Tasmania only Hobart, the city as before, and a postcode its bond medians give no figure for, saying so; the state
|
|
158
|
+
alone and a postcode with a bond median are answered from the bonds, as `area_rents` answers them, and Hobart's
|
|
159
|
+
answer points to the postcodes Hobart was lodged under that month, in `bond_medians_at`, without giving their
|
|
160
|
+
medians): interim ABS cover,
|
|
136
161
|
CC BY 4.0 - the median weekly rent paid in the postal area on Census night, 10 August 2021 (leases new and old,
|
|
137
162
|
every landlord), the capital's CPI rents index and ABS median sale prices, each with its period. None is a median
|
|
138
163
|
of new bonds or today's rent. A postal area under half privately rented carries "Mostly not private rentals: do not
|
|
139
164
|
quote as a market rent."; a small Census sample is marked; where fewer than 10 households stated their rent there is
|
|
140
165
|
no dollar median, only "Too few households for a median (N)". The answer carries `interim: true`, `census_period`,
|
|
141
|
-
`postal_area`, `cpi_rents` and `dwelling_prices`, and the state's page (/area/act/, /area/nt/, /area/tas/
|
|
166
|
+
`postal_area`, `cpi_rents` and `dwelling_prices`, and the state's page (/area/act/, /area/nt/, /area/tas/abs/ -
|
|
167
|
+
/area/tas/ until 0.16.0, now the index of Tasmania's bond pages).
|
|
142
168
|
- `rent_check` places no rent against either: not an Australian-dollar rent against NZ$ figures, and not against a
|
|
143
169
|
2021 Census median.
|
|
144
170
|
|
|
@@ -207,6 +233,24 @@ later than the current one; otherwise, or with `DWELLDELTA_OFFLINE=1`, the bundl
|
|
|
207
233
|
tools.dwelldelta.com.au, the state's page for the state's own figure, else null), `pages` and `cite_as` (null when
|
|
208
234
|
every figure is refused); the text gains `Page:` and `Cite as:` lines. Results stay text only, readable by clients
|
|
209
235
|
on every protocol version the server accepts. No earlier field changes.
|
|
236
|
+
- (From 0.16.0.) A WA answer's `cite_as`, and its text's `Cite as:` line, say "Median calculated by DwellDelta
|
|
237
|
+
from bond records." before the source ("Medians calculated ..." where the answer gives more than one median; one
|
|
238
|
+
given and the other places matched refused is "Median"): the Government of Western Australia publishes one row per
|
|
239
|
+
bond and no medians, so the line quoted alone no longer credits it with DwellDelta's figure. The area page's line,
|
|
240
|
+
always one place's, says the same. The field's meaning is unchanged, and no other state's line changes: theirs are
|
|
241
|
+
their publishers' own medians.
|
|
242
|
+
- (From 0.16.0.) Tasmania's bond medians (see "Rents by area" above): `area_rents` takes `state: "TAS"`.
|
|
243
|
+
`property_rents` answers from them a Tasmanian postcode with a median, the state alone, and a suburb the month's
|
|
244
|
+
bonds were lodged under that no other file holds ("Sandy Bay"), or any with ", TAS" ("Kingston, TAS"), for its whole
|
|
245
|
+
postcode; a name lodged in several postcodes is listed, not chosen. A name another state's file holds ("Kingston",
|
|
246
|
+
"Perth") answers as in 0.15.0, with one line, and `also_in_tasmania`, pointing to the Tasmanian postcode, no figure
|
|
247
|
+
(in `rent_check`'s structured result too). The names are the month's own: a missing `also_in_tasmania` only means no
|
|
248
|
+
bond was lodged under the name that month, not that the name is not in Tasmania. "Hobart" keeps its 0.15.0 meaning,
|
|
249
|
+
the city, from the interim ABS file, with `bond_medians_at` pointing to the postcodes Hobart was lodged under that
|
|
250
|
+
month. A name with a Tasmanian postcode ("Hobart 7004") is answered for that postcode as asked, exactly as the
|
|
251
|
+
postcode alone, with a `place_note` where the month's bonds put the name under another postcode. A postcode, or a
|
|
252
|
+
suburb, its bonds give no median for is answered from the interim ABS file, its `Place:` line saying why. `rent_check` places a rent against a Tasmanian bond median, its `local.quarter` null and its month in
|
|
253
|
+
`local.month` and `local.month_words`. No released field changes meaning.
|
|
210
254
|
- The server sends `instructions` in its initialize result: what it holds, when it applies, how to cite it, its limits.
|
|
211
255
|
- A URL in an answer's text is never followed by punctuation run into it: one that would be is written `<...>`. This
|
|
212
256
|
changes the `Cite:` line's text: its URLs now read `<https://...>` where a `;` or `.` follows them.
|
|
@@ -245,8 +289,8 @@ published data file. The structured result says the same, in new fields; every f
|
|
|
245
289
|
|
|
246
290
|
- each entry of `sources` adds `licence_id`, `licence_url`, `source_url`, `source_notice_url`, `feed_url` and
|
|
247
291
|
`period`. `source_url` is only ever an address of the data's own page that the data file itself holds: for WA
|
|
248
|
-
the National Housing Data Exchange dataset page, for SA the data.sa.gov.au dataset page, for
|
|
249
|
-
page in its source line. It is null
|
|
292
|
+
the National Housing Data Exchange dataset page, for SA the data.sa.gov.au dataset page, for Tasmania data.gov.au's
|
|
293
|
+
listing of the dataset, for Victoria the DataVic page in its source line. It is null
|
|
250
294
|
where the file holds none - DCJ's files (NSW rents, rents by type, sale prices), the RTA's (Queensland), the ABS
|
|
251
295
|
rents index and the indicators snapshot. DCJ's and the RTA's files name only a copyright notice
|
|
252
296
|
(https://dcj.nsw.gov.au/statements/copyright-and-disclaimer.html, which DCJ's attribution also names, and
|
|
@@ -264,7 +308,8 @@ published data file. The structured result says the same, in new fields; every f
|
|
|
264
308
|
rents), and the ABS monthly rents index (`rent_check`) three months after its latest month (two to 0.14.0, which
|
|
265
309
|
flagged every January overdue: the ABS releases November's figures in early January). From 0.15.0, New Zealand's MBIE
|
|
266
310
|
month (`property_rents` with NZ) is overdue three months after it, and the ACT, NT and Tasmania interim cover
|
|
267
|
-
three months after its rents index month (to 0.14.0 neither carried a due date);
|
|
311
|
+
three months after its rents index month (to 0.14.0 neither carried a due date); from 0.16.0, Tasmania's bond
|
|
312
|
+
month four months after it; the interim cover's 2021 Census figures are fixed until the next
|
|
268
313
|
Census, and are not flagged, and its ABS sale-price quarter is not checked for staleness (the flag follows the
|
|
269
314
|
rents index month alone). An overdue answer opens with a `STALE:` line giving the reason (through `property_rents`, the
|
|
270
315
|
line after its `Place:` line), and its `Cite:` line ends `; STALE.` - as an old snapshot's does (the interim cover
|
package/area-rents-tool.mjs
CHANGED
|
@@ -8,10 +8,16 @@
|
|
|
8
8
|
*
|
|
9
9
|
* SA's file may hold one quarter only: then compared_with is null, and no answer names a quarter it is compared with.
|
|
10
10
|
*
|
|
11
|
+
* From 0.16.0, Tasmania (postcodes, calculated by DwellDelta from the Department of Justice's bond records, private
|
|
12
|
+
* housing only, tools.dwelldelta.com.au/market/tas-rents.json; CC BY 4.0 as data.gov.au lists it, the file's
|
|
13
|
+
* licence_note). Its file is a MONTH's, not a quarter's: it has month and month_words and no quarter, so a Tasmanian
|
|
14
|
+
* answer's quarter is null and it carries month and month_words, fields of its own (a released field keeps its
|
|
15
|
+
* meaning: quarter is never a month). A suburb name its bonds were lodged under that month finds the whole postcode.
|
|
16
|
+
*
|
|
11
17
|
* One state per call, never pooled: each publisher measures in its own way, and the WA medians are our own
|
|
12
18
|
* calculation, so every answer carries that state's own source line, what was changed, and its limits.
|
|
13
19
|
*
|
|
14
|
-
* Loaded like vic_rents: DWELLDELTA_STATE_RENTS_DIR (a folder holding the
|
|
20
|
+
* Loaded like vic_rents: DWELLDELTA_STATE_RENTS_DIR (a folder holding the five files), else the owner's live store,
|
|
15
21
|
* else the published file (fetched once at start - one public file each; nothing about the user or their questions is
|
|
16
22
|
* sent - and used if well formed, for the right state, and not older than the bundled copy), else the copy bundled at
|
|
17
23
|
* pack time. DWELLDELTA_OFFLINE=1 never fetches. The data changes once a quarter, so every answer states its quarter.
|
|
@@ -26,7 +32,8 @@ import { loadJson, envelope, ToolError, FOOTER, FETCH_TIMEOUT_MS, feedSource, CA
|
|
|
26
32
|
figureFields, nWords, citeLine, staleNote, flagged, refusalMark, isRecord, passes, readChecked, quiet,
|
|
27
33
|
warnPublished, fromCopy } from "./tools.mjs";
|
|
28
34
|
import { quarterKey } from "./vic-rents-tool.mjs";
|
|
29
|
-
import { rentPage, citeFields, withPlace } from "./pages.mjs";
|
|
35
|
+
import { rentPage, citeFields, withPlace, listedLicence, LISTED } from "./pages.mjs";
|
|
36
|
+
import { checkFetched, MAPS } from "./feed-text.mjs";
|
|
30
37
|
|
|
31
38
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
32
39
|
const LIVE_DIR = join(HERE, "..", "..", "dwelldelta-data", "market");
|
|
@@ -47,16 +54,41 @@ export const STATES = {
|
|
|
47
54
|
SA: { file: "sa-rents.json", name: "South Australia", notice_is_data: true,
|
|
48
55
|
hint: "South Australian rents are by suburb, as the SA Housing Trust names it (area: \"Mount Gambier\"; part " +
|
|
49
56
|
"of a name works). There are no councils in this file." },
|
|
57
|
+
// Tasmania (0.16.0): a month's file. Its source_notice is data.gov.au's listing of the dataset (the Department
|
|
58
|
+
// publishes the workbooks there), so it is where the data is, never a copyright notice.
|
|
59
|
+
TAS: { file: "tas-rents.json", name: "Tasmania", notice_is_data: true, monthly: true,
|
|
60
|
+
hint: "Tasmanian rents are by postcode (area: \"7000\"), or by a suburb name the month's bonds were lodged " +
|
|
61
|
+
"under (area: \"Sandy Bay\"; part of a name works), answered for its whole postcode. There are no " +
|
|
62
|
+
"councils in this file." },
|
|
50
63
|
};
|
|
51
64
|
/** Each state's small-sample rule (tools.mjs SAMPLE_RULES): below it a figure is refused, never given. */
|
|
52
65
|
export const RULES = { NSW: SAMPLE_RULES.NSW_RENTS, QLD: SAMPLE_RULES.QLD_RENTS, WA: SAMPLE_RULES.WA_RENTS,
|
|
53
|
-
SA: SAMPLE_RULES.SA_RENTS };
|
|
66
|
+
SA: SAMPLE_RULES.SA_RENTS, TAS: SAMPLE_RULES.TAS_RENTS };
|
|
54
67
|
/** Rows shown in one answer; a wider match says how many more there are instead of dropping them silently. */
|
|
55
68
|
export const MAX_ROWS = 25;
|
|
56
69
|
|
|
70
|
+
/** A month's file (Tasmania) says so in its own fields - month "2026-08", month_words "August 2026" - and has no quarter. */
|
|
71
|
+
export const isMonthly = (state) => STATES[state]?.monthly === true;
|
|
72
|
+
const YM = /^(\d{4})-(0[1-9]|1[0-2])$/;
|
|
73
|
+
const MONTH_NAMES = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October",
|
|
74
|
+
"November", "December"];
|
|
75
|
+
/**
|
|
76
|
+
* A file's period as a number to order copies by (later is larger), or 0 where it is not one this state's file gives:
|
|
77
|
+
* a quarter's file its quarter; a month's its month, with no quarter and month_words that say the same month in full
|
|
78
|
+
* ("2026-08", "August 2026", as dwelldelta-local build_tas_rents_feed.py writes them).
|
|
79
|
+
*/
|
|
80
|
+
export const periodKey = (f, state) => {
|
|
81
|
+
if (!isMonthly(state)) return quarterKey(f?.quarter);
|
|
82
|
+
const m = YM.exec(String(f?.month ?? ""));
|
|
83
|
+
return m && f.quarter === undefined && f.month_words === `${MONTH_NAMES[Number(m[2]) - 1]} ${m[1]}`
|
|
84
|
+
? Number(m[1]) * 100 + Number(m[2]) : 0;
|
|
85
|
+
};
|
|
86
|
+
/** The period an answer names: "Jun 2026", or Tasmania's "August 2026". */
|
|
87
|
+
export const periodOf = (f, state) => (isMonthly(state) ? f.month_words : f.quarter);
|
|
88
|
+
|
|
57
89
|
// A row of its lists that is not a row is skipped where the tool reads them, and a row's name of another type matches
|
|
58
90
|
// nothing (tools.mjs, "What a copy must be before it answers"): the checks here are the ones the feed always had.
|
|
59
|
-
const wellFormed = (f, state) => f && f.state === state &&
|
|
91
|
+
const wellFormed = (f, state) => f && f.state === state && periodKey(f, state) > 0
|
|
60
92
|
&& Array.isArray(f.areas) && f.areas.length > 0 && Array.isArray(f.councils) && Array.isArray(f.regions)
|
|
61
93
|
&& f.state_total && Array.isArray(f.limits) && f.licence && f.attribution && f.changes_made;
|
|
62
94
|
|
|
@@ -72,19 +104,23 @@ export async function loadAreaRents(state, { env = process.env, fetchImpl = glob
|
|
|
72
104
|
}
|
|
73
105
|
if (existsSync(join(liveDir, file))) return fromCopy(await read(join(liveDir, file)), "feed", "live");
|
|
74
106
|
const shipped = (await read(join(bundledDir, file))).copy;
|
|
107
|
+
let note = null;
|
|
75
108
|
if (env.DWELLDELTA_OFFLINE !== "1" && typeof fetchImpl === "function") {
|
|
76
109
|
try {
|
|
77
110
|
const res = await fetchImpl(PUBLISHED_BASE + file, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
|
78
|
-
const
|
|
111
|
+
const checked = checkFetched(res.ok ? await res.json() : null, { file, what, url: PUBLISHED_BASE + file, warn,
|
|
112
|
+
only: (g) => passes(wellFormed, g, state) && (!shipped || periodKey(g, state) >= periodKey(shipped, state)) });
|
|
113
|
+
const got = checked.got;
|
|
114
|
+
note = checked.note;
|
|
79
115
|
if (got != null && !passes(wellFormed, got, state)) warnPublished(warn, what, PUBLISHED_BASE + file, shipped);
|
|
80
|
-
if (passes(wellFormed, got, state) && (!shipped ||
|
|
81
|
-
return { feed: got, origin: "published" };
|
|
116
|
+
if (passes(wellFormed, got, state) && (!shipped || periodKey(got, state) >= periodKey(shipped, state))) {
|
|
117
|
+
return { feed: got, origin: "published", ...(note ? { note } : {}) };
|
|
82
118
|
}
|
|
83
119
|
} catch {
|
|
84
|
-
// Offline, blocked or slow: the bundled copy answers, and its quarter says how current it is.
|
|
120
|
+
// Offline, blocked or slow: the bundled copy answers, and its quarter (or month) says how current it is.
|
|
85
121
|
}
|
|
86
122
|
}
|
|
87
|
-
return { feed: shipped, origin: shipped ? "bundled" : null };
|
|
123
|
+
return { feed: shipped, origin: shipped ? "bundled" : null, ...(note ? { note } : {}) };
|
|
88
124
|
}
|
|
89
125
|
|
|
90
126
|
/**
|
|
@@ -95,7 +131,7 @@ export async function loadAreaRents(state, { env = process.env, fetchImpl = glob
|
|
|
95
131
|
export async function loadAllAreaRents(opts) {
|
|
96
132
|
const loaded = await Promise.all(Object.keys(STATES).map((s) => loadAreaRents(s, opts)));
|
|
97
133
|
return withRefused(Object.fromEntries(Object.keys(STATES).map((s, i) =>
|
|
98
|
-
[s, loaded[i].feed ? { ...loaded[i].feed, origin: loaded[i].origin } : null])), Object.keys(STATES), loaded);
|
|
134
|
+
[s, loaded[i].feed ? { ...loaded[i].feed, origin: loaded[i].origin, ...(loaded[i].note ? { text_check: loaded[i].note } : {}) } : null])), Object.keys(STATES), loaded);
|
|
99
135
|
}
|
|
100
136
|
/** feeds, with the refused copies of states[i] (loaded[i].refused) as a property that is not enumerable. */
|
|
101
137
|
export function withRefused(feeds, states, loaded) {
|
|
@@ -123,8 +159,24 @@ const whyNone = (r) => r.withheld ?? (r.new_bonds == null ? "too few bonds"
|
|
|
123
159
|
export const rentFigure = (r, name, rule) => judgeFigure(r, { name, median: "median_weekly_rent_aud", count: "new_bonds",
|
|
124
160
|
band: r?.new_bonds_range != null ? "new_bonds_range" : "new_bonds_band", rule,
|
|
125
161
|
why: r && r.median_weekly_rent_aud == null ? whyNone(r) : null });
|
|
126
|
-
/** "Quarter: Jun 2026, against Jun 2025." - or, where no year-before figures are held (SA, one quarter
|
|
162
|
+
/** "Quarter: Jun 2026, against Jun 2025." - or, where no year-before figures are held (SA, one quarter; Tasmania, one
|
|
163
|
+
* month), says so. */
|
|
127
164
|
const against = (f) => (f.compared_with ? `, against ${f.compared_with}` : " (no figures for a year before are held)");
|
|
165
|
+
/** "Quarter: Jun 2026" or, for a month's file, "Month: August 2026". */
|
|
166
|
+
const periodWords = (f, state) => (isMonthly(state) ? `Month: ${f.month_words}` : `Quarter: ${f.quarter}`);
|
|
167
|
+
|
|
168
|
+
/** A name in the bond records' capitals as the site writes it (area/lookup.mjs titled): "SOUTH HOBART" is South Hobart. */
|
|
169
|
+
export const titled = (name) => String(name).toLowerCase().replace(/(^|[\s'-])([a-z])/g, (m, a, b) => a + b.toUpperCase())
|
|
170
|
+
.replace(/\bMc([a-z])/g, (m, c) => `Mc${c.toUpperCase()}`);
|
|
171
|
+
/** Lodged-under names shown on a Tasmanian postcode's line; the rest are counted. */
|
|
172
|
+
export const MAX_LODGED = 8;
|
|
173
|
+
/** " Its bonds were lodged under: Glebe, Hobart." - the suburb names a Tasmanian postcode's bonds were lodged under. */
|
|
174
|
+
const lodged = (r) => {
|
|
175
|
+
const names = (Array.isArray(r?.suburbs) ? r.suburbs : []).filter((n) => typeof n === "string").map(titled);
|
|
176
|
+
if (!names.length) return "";
|
|
177
|
+
const more = names.length > MAX_LODGED ? ` and ${names.length - MAX_LODGED} more` : "";
|
|
178
|
+
return ` Its bonds were lodged under: ${names.slice(0, MAX_LODGED).join(", ")}${more}.`;
|
|
179
|
+
};
|
|
128
180
|
|
|
129
181
|
function line(r, name, rule = null) {
|
|
130
182
|
if (r.median_weekly_rent_aud == null) return `${name}: no median (${whyNone(r)}).`;
|
|
@@ -201,6 +253,32 @@ export const spellings = (name) => {
|
|
|
201
253
|
return new Set([n, n.replace(/\bmt\.?\s/g, "mount "), n.replace(/\bmount\s/g, "mt ")]);
|
|
202
254
|
};
|
|
203
255
|
|
|
256
|
+
/**
|
|
257
|
+
* Tasmania's postcodes for a suburb name (0.16.0): those whose bonds were lodged under exactly that name that month (or
|
|
258
|
+
* its "Mt"/"Mount" twin), else those under a name containing it: { rows, exact }. A month's records do not name every
|
|
259
|
+
* suburb: a name no bond was lodged under that month finds nothing, and its postcode is the way to ask.
|
|
260
|
+
*/
|
|
261
|
+
export function tasPostcodes(name, feed) {
|
|
262
|
+
const want = spellings(name);
|
|
263
|
+
const rows = (feed?.areas ?? []).filter(isRecord);
|
|
264
|
+
const names = (r) => (Array.isArray(r.suburbs) ? r.suburbs.filter((n) => typeof n === "string") : []);
|
|
265
|
+
const exact = rows.filter((r) => names(r).some((n) => want.has(norm(n))));
|
|
266
|
+
if (exact.length) return { rows: exact, exact: true };
|
|
267
|
+
const w = norm(name);
|
|
268
|
+
return { rows: w ? rows.filter((r) => names(r).some((n) => norm(n).includes(w))) : [], exact: false };
|
|
269
|
+
}
|
|
270
|
+
/** The note when a Tasmanian name was answered for its postcode(s): which, and that the figures are the whole postcode's. */
|
|
271
|
+
export function tasNote(name, rows, exact, feed) {
|
|
272
|
+
if (exact && rows.length === 1) {
|
|
273
|
+
const lodgedAs = (Array.isArray(rows[0].suburbs) ? rows[0].suburbs : []).find((s) => typeof s === "string" && spellings(name).has(norm(s)));
|
|
274
|
+
const n = lodgedAs ? titled(lodgedAs) : String(name).trim();
|
|
275
|
+
return `${n} is in postcode ${rows[0].area}: its bonds for ${feed.month_words} were lodged under that postcode. ` +
|
|
276
|
+
`These figures are for the whole postcode, not ${n} alone.`;
|
|
277
|
+
}
|
|
278
|
+
return `Postcodes whose bonds for ${feed.month_words} were lodged under a suburb ${exact ? "of that name" : "whose name " +
|
|
279
|
+
"holds that"}: ${rows.map((r) => r.area).join(", ")}. A postcode is not a suburb: these figures are for each whole postcode.`;
|
|
280
|
+
}
|
|
281
|
+
|
|
204
282
|
/**
|
|
205
283
|
* An NSW name the suburb list places in more than one postcode ("Alison": 2259 and 2420), as a ToolError that says so
|
|
206
284
|
* and lists every one, none chosen - or null for a name in one postcode or none (0.13.0). Until then area_rents said
|
|
@@ -256,12 +334,12 @@ export function councilToo(wanted, councils) {
|
|
|
256
334
|
* With dwelling_type or bedrooms the answer comes from that state's by-type file instead (byType[state], loaded at
|
|
257
335
|
* start by loadAllRentsByType) - see byTypeResult below.
|
|
258
336
|
*/
|
|
259
|
-
export function areaRentsResult({ state, area, council, dwelling_type, bedrooms } = {}, feeds, now = new Date(),
|
|
337
|
+
export function areaRentsResult({ state, area, council, dwelling_type, bedrooms, tasName = null } = {}, feeds, now = new Date(),
|
|
260
338
|
{ nswSuburbs = [], byType = {}, hosted = false } = {}) {
|
|
261
339
|
const info = STATES[state];
|
|
262
340
|
if (!info) {
|
|
263
341
|
throw new ToolError(`No area rents for ${JSON.stringify(state)}.`,
|
|
264
|
-
`Call area_rents with state NSW, QLD, WA or
|
|
342
|
+
`Call area_rents with state NSW, QLD, WA, SA or TAS. Victoria is in vic_rents; the ACT and the Northern ` +
|
|
265
343
|
`Territory are not covered.`);
|
|
266
344
|
}
|
|
267
345
|
const feed = feeds[state];
|
|
@@ -277,7 +355,18 @@ export function areaRentsResult({ state, area, council, dwelling_type, bedrooms
|
|
|
277
355
|
let areas = [], councils = [], regions = [];
|
|
278
356
|
let resolved = null;
|
|
279
357
|
if (area != null && String(area).trim()) {
|
|
280
|
-
|
|
358
|
+
// Tasmania's areas are postcodes: a name is looked for among the suburb names each postcode's bonds were lodged
|
|
359
|
+
// under that month, and answered for the whole postcode, with a note saying so (0.16.0).
|
|
360
|
+
const byName = state === "TAS" && !/^\d+$/.test(String(area).trim());
|
|
361
|
+
areas = byName ? [] : match(feed.areas, "area", area);
|
|
362
|
+
if (byName) {
|
|
363
|
+
const found = tasPostcodes(area, feed);
|
|
364
|
+
areas = found.rows;
|
|
365
|
+
if (areas.length) resolved = { note: tasNote(area, areas, found.exact, feed) };
|
|
366
|
+
} else if (state === "TAS" && tasName != null && String(tasName).trim() && areas.length === 1) {
|
|
367
|
+
// A postcode asked with a suburb's name (property_rents "Hobart 7000"; 0.16.0): the same whole-postcode note.
|
|
368
|
+
resolved = { note: tasNote(tasName, areas, true, feed) };
|
|
369
|
+
}
|
|
281
370
|
if (!areas.length && state === "NSW") {
|
|
282
371
|
resolved = nswResolve(area, nswSuburbs, feed);
|
|
283
372
|
if (resolved) {
|
|
@@ -288,6 +377,11 @@ export function areaRentsResult({ state, area, council, dwelling_type, bedrooms
|
|
|
288
377
|
const several = resolved ? null : nswSeveralPostcodes(area, nswSuburbs, feed);
|
|
289
378
|
if (several) throw several;
|
|
290
379
|
}
|
|
380
|
+
if (!areas.length && byName) {
|
|
381
|
+
throw new ToolError(`No bond lodged in ${info.name} in ${feed.month_words} names a suburb ${JSON.stringify(area)} ` +
|
|
382
|
+
"(nor one whose name holds it).", `${info.hint} ${feed.areas.length.toLocaleString("en-AU")} postcode rows are ` +
|
|
383
|
+
"held; a suburb no bond was lodged under that month is not among the names, so give its postcode.");
|
|
384
|
+
}
|
|
291
385
|
if (!areas.length) {
|
|
292
386
|
const named = state === "NSW" ? nswPostcodes(area, nswSuburbs, feed) : [];
|
|
293
387
|
throw new ToolError(`No ${info.name} ${kind} matches ${JSON.stringify(area)}.`,
|
|
@@ -311,8 +405,12 @@ export function areaRentsResult({ state, area, council, dwelling_type, bedrooms
|
|
|
311
405
|
const label = shownAreas.length === 1 && !councils.length ? `${shownAreas[0].area} (${kind}), ${info.name}`
|
|
312
406
|
: whole ? info.name : `${info.name}, ${shownAreas.length + councils.length} places`;
|
|
313
407
|
const cite = citeFields({ state, places: councils.length ? [] : places, whole,
|
|
314
|
-
what: `Median weekly rent of new bonds${byKind ? " by dwelling type" : ""}, ${label}`, period: feed
|
|
315
|
-
by: feed.rights_holder ?? feed.source, licence: feed.licence,
|
|
408
|
+
what: `Median weekly rent of new bonds${byKind ? " by dwelling type" : ""}, ${label}`, period: periodOf(feed, state),
|
|
409
|
+
by: feed.rights_holder ?? feed.source, licence: listedLicence(state, feed.licence),
|
|
410
|
+
allRefused: res.structured.all_refused === true,
|
|
411
|
+
// "Medians calculated by ..." where the answer gives more than one median; one median, or one given and the rest
|
|
412
|
+
// refused (too few bonds), is "Median" (review of #105: counting places matched said "Medians" for one figure).
|
|
413
|
+
calculated: feed.derived === true, several: res.structured.figures.filter((f) => !f.refusal).length > 1 });
|
|
316
414
|
if (councils.length) cite.pages = places.filter((p) => p.url).map((p) => ({ place: p.name, url: p.url }));
|
|
317
415
|
const note = resolved?.note ?? null;
|
|
318
416
|
return { text: withPlace(res.text, { note, ...cite }, FOOTER),
|
|
@@ -331,22 +429,37 @@ export function areaRentsResult({ state, area, council, dwelling_type, bedrooms
|
|
|
331
429
|
councils = councils.slice(0, MAX_ROWS);
|
|
332
430
|
const rule = RULES[state];
|
|
333
431
|
const feedUrl = PUBLISHED_BASE + info.file;
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
432
|
+
const monthly = isMonthly(state);
|
|
433
|
+
// A month's file is dated by its month, "2026-08", as New Zealand's answers are; a quarter's by its quarter.
|
|
434
|
+
const asOf = monthly ? feed.month : feed.quarter;
|
|
435
|
+
const env = envelope({ sources: [feedSource(feed, feedUrl, asOf, { noticeIsData: info.notice_is_data === true })],
|
|
436
|
+
dataAsOf: asOf, origin: feed.origin ?? null, check: feed.text_check ?? null,
|
|
437
|
+
cadence: monthly ? CADENCE.tas_monthly : CADENCE.rents_quarterly }, now);
|
|
438
|
+
// Tasmania's whole-state answer also gives the file's state_breakdown: the state's medians by bedrooms and by dwelling
|
|
439
|
+
// type, in the records' own labels - for the state alone; no postcode has them.
|
|
440
|
+
const breakdown = monthly && whole && isRecord(feed.state_breakdown) ? feed.state_breakdown : null;
|
|
441
|
+
const plural = (b) => (b === "1" ? "1 bedroom" : `${b} bedrooms`);
|
|
442
|
+
const byBeds = (Array.isArray(breakdown?.by_bedrooms) ? breakdown.by_bedrooms : []).filter(isRecord)
|
|
443
|
+
.map((r) => [`${info.name}, ${plural(String(r.bedrooms))}`, r]);
|
|
444
|
+
const byKindRows = (Array.isArray(breakdown?.by_dwelling_type) ? breakdown.by_dwelling_type : []).filter(isRecord)
|
|
445
|
+
.map((r) => [`${info.name}, ${r.dwelling_type}`, r]);
|
|
337
446
|
// Every line, in the order the answer gives them: its name, its row.
|
|
338
|
-
const shown = [...(whole ? [[`${info.name} (whole state)`, feed.state_total]] : []),
|
|
447
|
+
const shown = [...(whole ? [[`${info.name} (whole state)`, feed.state_total]] : []), ...byBeds, ...byKindRows,
|
|
339
448
|
...regions.map((r) => [`${r.region} (region)`, r]), ...councils.map((r) => [`${r.council} (council)`, r]),
|
|
340
449
|
...areas.map((r) => [`${r.area} (${kind})`, r])];
|
|
341
450
|
const figures = shown.map(([name, r]) => rentFigure(r, name, rule));
|
|
342
451
|
// Each row as the file gives it, plus its own refusal marker (a copy: the loaded feed is never written to).
|
|
343
452
|
const judged = new Map(shown.map(([, r], i) => [r, figures[i]]));
|
|
344
453
|
const marked = (r) => ({ ...r, ...refusalMark(judged.get(r)) });
|
|
454
|
+
const breakdownAt = whole ? 1 : -1;
|
|
345
455
|
const text = [
|
|
346
456
|
...staleNote(env),
|
|
347
|
-
`${feed.what}.
|
|
457
|
+
`${feed.what}. ${periodWords(feed, state)}${against(feed)}.`,
|
|
348
458
|
"",
|
|
349
|
-
...shown.
|
|
459
|
+
...shown.flatMap(([name, r], i) => [
|
|
460
|
+
...(i === breakdownAt && byBeds.length + byKindRows.length ? [`By bedrooms and by dwelling type, for ${info.name} ` +
|
|
461
|
+
"as a whole only, in the records' own labels (no postcode has them):"] : []),
|
|
462
|
+
line(r, name, rule) + (state === "TAS" && areas.includes(r) ? lodged(r) : "")]),
|
|
350
463
|
...dropped,
|
|
351
464
|
...(whole ? ["", `${feed.areas.length.toLocaleString("en-AU")} ${kind} rows` +
|
|
352
465
|
`${feed.councils.length ? ` and ${feed.councils.length} councils` : ""} are available: call again with area` +
|
|
@@ -357,13 +470,21 @@ export function areaRentsResult({ state, area, council, dwelling_type, bedrooms
|
|
|
357
470
|
"",
|
|
358
471
|
`Source: ${feed.attribution}`,
|
|
359
472
|
`What DwellDelta changed: ${feed.changes_made}`,
|
|
360
|
-
citeLine({ source: feed.source, period: feed.compared_with ? `${feed
|
|
361
|
-
licence: feed.licence, n: nWords(figures, rule.unit), url: env.sources[0].source_url,
|
|
473
|
+
citeLine({ source: feed.source, period: feed.compared_with ? `${periodOf(feed, state)} (against ${feed.compared_with})` : periodOf(feed, state),
|
|
474
|
+
licence: feed.licence, listed: LISTED[state] ?? null, n: nWords(figures, rule.unit), url: env.sources[0].source_url,
|
|
362
475
|
notice: env.sources[0].source_notice_url, feedUrl, stale: flagged(env) }),
|
|
363
476
|
FOOTER,
|
|
364
477
|
].join("\n");
|
|
365
|
-
|
|
366
|
-
|
|
478
|
+
const markRows = (rows) => (Array.isArray(rows) ? rows.filter(isRecord).map(marked) : []);
|
|
479
|
+
return finish({ text, structured: { ...env, state, state_name: info.name, area_kind: kind, quarter: feed.quarter ?? null,
|
|
480
|
+
compared_with: feed.compared_with,
|
|
481
|
+
// Tasmania (0.16.0): its month, and the state's breakdown (whole state only).
|
|
482
|
+
// licence_note: where the licence was read (Tasmania: as data.gov.au lists it).
|
|
483
|
+
...(monthly ? { month: feed.month, month_words: feed.month_words,
|
|
484
|
+
licence_note: feed.licence_note ?? null,
|
|
485
|
+
state_breakdown: breakdown ? { by_bedrooms: markRows(breakdown.by_bedrooms),
|
|
486
|
+
by_dwelling_type: markRows(breakdown.by_dwelling_type) } : null } : {}),
|
|
487
|
+
derived: feed.derived === true,
|
|
367
488
|
state_total: whole ? marked(feed.state_total) : null, regions: regions.map(marked),
|
|
368
489
|
councils: councils.map(marked), areas: areas.map(marked),
|
|
369
490
|
truncated: dropped.length > 0, limits: feed.limits, changes_made: feed.changes_made,
|
|
@@ -419,26 +540,30 @@ export async function loadRentsByType(state, { env = process.env, fetchImpl = gl
|
|
|
419
540
|
}
|
|
420
541
|
if (existsSync(join(liveDir, file))) return fromCopy(await read(join(liveDir, file)), "feed", "live");
|
|
421
542
|
const shipped = byTypeDir ? (await read(join(byTypeDir, file))).copy : null;
|
|
543
|
+
let note = null;
|
|
422
544
|
if (env.DWELLDELTA_OFFLINE !== "1" && typeof fetchImpl === "function") {
|
|
423
545
|
try {
|
|
424
546
|
const res = await fetchImpl(PUBLISHED_BASE + file, { signal: AbortSignal.timeout(BY_TYPE_TIMEOUT_MS) });
|
|
425
|
-
const
|
|
547
|
+
const checked = checkFetched(res.ok ? await res.json() : null, { file, what, url: PUBLISHED_BASE + file, warn,
|
|
548
|
+
maps: MAPS[file], only: (g) => passes(wellFormedByType, g, state) && (!shipped || quarterKey(g.quarter) >= quarterKey(shipped.quarter)) });
|
|
549
|
+
const got = checked.got;
|
|
550
|
+
note = checked.note;
|
|
426
551
|
if (passes(wellFormedByType, got, state) && (!shipped || quarterKey(got.quarter) >= quarterKey(shipped.quarter))) {
|
|
427
|
-
return { feed: got, origin: "published" };
|
|
552
|
+
return { feed: got, origin: "published", ...(note ? { note } : {}) };
|
|
428
553
|
}
|
|
429
554
|
if (got != null && !passes(wellFormedByType, got, state)) warnPublished(warn, what, PUBLISHED_BASE + file, shipped);
|
|
430
555
|
} catch {
|
|
431
556
|
// Offline, blocked or slow: the bundled copy answers where there is one; else a by-type question says what to do.
|
|
432
557
|
}
|
|
433
558
|
}
|
|
434
|
-
return { feed: shipped, origin: shipped ? "bundled" : null };
|
|
559
|
+
return { feed: shipped, origin: shipped ? "bundled" : null, ...(note ? { note } : {}) };
|
|
435
560
|
}
|
|
436
561
|
|
|
437
562
|
/** Both states' by-type files: { NSW: file-with-origin | null, QLD: ... }. It never rejects. */
|
|
438
563
|
export async function loadAllRentsByType(opts) {
|
|
439
564
|
const states = Object.keys(BY_TYPE);
|
|
440
565
|
const loaded = await Promise.all(states.map((s) => loadRentsByType(s, opts).catch(() => ({ feed: null }))));
|
|
441
|
-
return withRefused(Object.fromEntries(states.map((s, i) => [s, loaded[i].feed ? { ...loaded[i].feed, origin: loaded[i].origin } : null])),
|
|
566
|
+
return withRefused(Object.fromEntries(states.map((s, i) => [s, loaded[i].feed ? { ...loaded[i].feed, origin: loaded[i].origin, ...(loaded[i].note ? { text_check: loaded[i].note } : {}) } : null])),
|
|
442
567
|
states, loaded);
|
|
443
568
|
}
|
|
444
569
|
|
|
@@ -570,9 +695,16 @@ function qldAsked(file, dwelling_type, bedrooms) {
|
|
|
570
695
|
function byTypeResult({ state, info, feed, dwelling_type, bedrooms, whole, areas, councils, file, refusedFile = null,
|
|
571
696
|
hosted = false }, now) {
|
|
572
697
|
if (!BY_TYPE[state]) {
|
|
573
|
-
|
|
698
|
+
// Tasmania (0.16.0): the state's medians by bedrooms and dwelling type come only in its whole-state answer.
|
|
699
|
+
throw new ToolError(state === "TAS" ? (whole ? "Tasmania's medians by bedrooms and by dwelling type are given only in " +
|
|
700
|
+
"its whole-state answer, all of them together, not one asked for by dwelling_type or bedrooms."
|
|
701
|
+
: "Tasmania's rents are not published by dwelling type or bedrooms for a postcode.")
|
|
702
|
+
: `${info.name} rents are not published by dwelling type or bedrooms.`, state === "WA"
|
|
574
703
|
? "WA's bond records carry neither. Call area_rents for WA without dwelling_type and bedrooms: every WA figure " +
|
|
575
704
|
"is all dwellings together."
|
|
705
|
+
: state === "TAS"
|
|
706
|
+
? "Every Tasmanian postcode's figure is all dwellings together. Call area_rents with state TAS alone: it gives " +
|
|
707
|
+
"Tasmania's medians by bedrooms and by dwelling type for the state as a whole."
|
|
576
708
|
: `DwellDelta publishes ${info.name}'s rents for all dwellings together only. Call area_rents for ${state} ` +
|
|
577
709
|
`without dwelling_type and bedrooms: every ${state} figure is all dwellings together.`);
|
|
578
710
|
}
|
|
@@ -627,7 +759,7 @@ function byTypeResult({ state, info, feed, dwelling_type, bedrooms, whole, areas
|
|
|
627
759
|
if (truncated) lines.push(`${places.length - shown.length} more places match: narrow the name.`);
|
|
628
760
|
const feedUrl = PUBLISHED_BASE + BY_TYPE[state];
|
|
629
761
|
const env = envelope({ sources: [feedSource(file, feedUrl, file.quarter)], dataAsOf: file.quarter,
|
|
630
|
-
origin: file.origin ?? null, cadence: CADENCE.rents_quarterly }, now);
|
|
762
|
+
origin: file.origin ?? null, check: file.text_check ?? null, cadence: CADENCE.rents_quarterly }, now);
|
|
631
763
|
const text = [
|
|
632
764
|
...staleNote(env),
|
|
633
765
|
`${file.what}. Quarter: ${file.quarter}, against ${file.compared_with}.`,
|