Hi Ben,
Your query seems to be based on a different input ("GRCMAPLE-1" is not
included in the example XML document), and…> CREATE DB bullion-2 /home/bpracht/java/basex-10.4/ …by running this command, you are creating a database with all XML documents found in the given filesystem path (that’s why your database is not empty). The attached query might give you a clue on how data can be prepared to get price/timestamp data displayed in the Plot visualization. After having run the query, you need to open the generated "test" database and enable the Plot visualization. Best, Christian On Tue, Jan 10, 2023 at 5:16 PM Ben Pracht <[email protected]> wrote: > > I think any non-stock database would work to show this, but below is the > code I was using. This is the part of the dialog I'd like to get working: > > https://i.imgur.com/ocGXjlP.png > > I apologize for the bad markering, but it shows the drop downs that > refer only to items in some other un-selected database. > > To recreate: > > 1. Please create a database. I kept most of the defaults: > > CREATE DB bullion-2 /home/bpracht/java/basex-10.4/ > > 2. Add a document: > > let $item := <item> > <vendor>sdbullion</vendor> > <img-url>https://sdbullion.com/media/catalog/product/cache/092a78d23e77560f092c3f80d85b629c/2/0/2022_50_1oz_9999_au_gml_core_rev_f_1_-min.jpg</img-url> > <detail-url>https://sdbullion.com/2022-1-oz-canadian-gold-maple-leaf-coin</detail-url> > <detail-title>2022 1 oz Gold Maple Leaf Coin BU</detail-title> > <schedule skus="GRC22MAPLE-1" timestamp="1672932572402"> > <tier quantity="1 - 9" cash-price="1930.26" cc-price="2010.69" > paypal-price="2010.69"/> > <tier quantity="10 - 19" cash-price="1925.26" cc-price="2005.48" > paypal-price="2005.48"/> > <tier quantity="20 - 99" cash-price="1920.26" cc-price="2000.27" > paypal-price="2000.27"/> > <tier quantity="100+" cash-price="1915.26" cc-price="1995.06" > paypal-price="1995.06"/> > </schedule> > </item> > let $add := db:add('bullion-2',$item,"test-item") > return $item > > 3. Test code: > > declare function > local:get-price-for-quantity($schedule,$price-type,$quantity as > xs:integer) { > let $matching-tier := for $tier in $schedule/tier > let $range := $tier/@quantity/data() > let $minimum := number(if > (contains($range,'-')) then > substring-before($range,'-') > else > substring-before($range,'+')) > let $maximum:= number(if > (contains($range,'-')) then > substring-after($range,'-') > else > xs:double("INF")) > return if ($quantity >= $minimum and > $quantity <= $maximum) then > $tier > else > () > > return $matching-tier/@*[local-name(.) = $price-type]/data() > }; > > for $schedule in collection("bullion")/item/schedule > let $timestamp := $schedule/@timestamp/data() > let $price-type := "cash-price" > let $price := local:get-price-for-quantity($schedule,"cash-price",1) > order by $timestamp ascending > return if ($schedule/@skus/data() = 'GRCMAPLE-1') then > ($timestamp,$price) > else > () > > The test code above should show the timestamp and price of the item. I > was going to put the timestamp as the X and the price as the Y, but I > can't figure out how. > > > Bonus concern: For some reason, it didn't create an empty database, but > rather had these other documents too: > > repo/http-www.functx.com-1.0/cxan.xml > repo/http-www.functx.com-1.0/expath-pkg.xml > webapp/WEB-INF/jetty.xml > webapp/WEB-INF/web.xml > etc/factbook.xml > etc/w3-catalog.xml > > > Thanks for your help, > > Ben
test.xq
Description: Binary data

