dependent Influxdb dashboard variables - influxdb

I have the following variable Brand:
import "influxdata/influxdb/schema"
schema.tagValues(bucket: "mybucket", tag: "brand")
and a variable ZIP:
import "influxdata/influxdb/schema"
schema.tagValues(bucket: "mybucket", tag: "zip")
I am using both in my query like:
...
|> filter(fn: (r) => r["brand"] == v.Brand)
|> filter(fn: (r) => r["zip"] == v.ZIP)
is it possible to have a dependency between the brand and the zip code? I other words, the zip codes should be filtered based on the selected brand.

Related

Clojure fill map using into

I need to fill map {:v '[], :f '[]), where v-array contains data from line that starts with v. How can I do this?
Example of file:
# comment
v 1.234 3.234 4.2345234
v 2.234 4.235235 6.2345
f 1 1 1
Expected result:
{:v [(1.234 3.234 4.2345234) (2.234 4.235235 6.2345)]
:f [(1 1 1)] }
My try:
(defn- file-lines
[filename]
(line-seq (io/reader filename)))
(defn- lines-with-data
[filename]
(->>
(file-lines filename)
(filter not-empty)
(filter #(not (str/starts-with? % "#")))))
(defn- create-model
[lines]
(doseq [data lines]
(into {:v '[] :f '[]}
(->>
(let [[type & remaining] data]
(case type
"v" [:v remaining]
"f" [:f remaining]))))))
(defn parse
[filename]
(->>
(lines-with-data filename)
(map #(str/split % #"\s+"))
(create-model)))
Exception:
user=> (p/parse "test.obj")
IllegalArgumentException Don't know how to create ISeq from: clojure.lang.Keyword clojure.lang.RT.seqFrom (RT.java:542)
(parse should be return result map)
I can repeat your error message like this:
(into {:v '[] :f '[]} [:v [:a :b]])
I can do what I think the program requires like this:
(assoc {:v '[] :f '[]} :v [:a :b])
;; => {:v [:a :b], :f []}
Here I just used [:a :b] instead of remaining. In your case remaining is a sequence of numbers, but it doesn't really matter.
As for the error message it is quite a bad one, that should be gone in coming versions of Clojure. Usually it is because you are presenting map with a keyword rather than something that seq can be called on. Here the message is coming from somewhere a bit deeper than I can comprehend.
Another construction that would work, and is I think what you wanted, is:
(into {:v '[] :f '[]} [[:v [:a :b]]])
into a map requires a sequence of map-entry. You forgot to wrap the single map-entry you were trying to place into the map. Result from my REPL:
{:v [:a :b], :f []}

How to make Automapper ignore records based on a value of a field

Hi I am trying to use Automapper 6 and want to ignore records based on specific value in a field. I wish there was a way to skip records like so:
CreateMap<CsfbFile, Common.Entities.FuturesExtract>()
.ForMember(dest => dest, opt => opt.Skip(source => source.Ccy == "BASE CURRENCY GRAND TOTAL"))
.ForMember(dest => dest.OptionValue, m => m.ResolveUsing(s => s.OptionsLmv + s.OptionsSmv));
Is there a way to do this ?
Thanks

Kendo MVC chart is displaying different dates than what we send in the JSON

We are having an issue where, in one of our Kendo charts we are developing to display some weekly data. The JSON that we're sending to the view looks like:
[
{"WeekofYear":45,"Value":96.08,"WeekBeginDate":"\/Date(1415422800000)\/"},
{"WeekofYear":46,"Value":97.40,"WeekBeginDate":"\/Date(1416027600000)\/"},
{"WeekofYear":47,"Value":96.50,"WeekBeginDate":"\/Date(1416632400000)\/"},
{"WeekofYear":48,"Value":93.93,"WeekBeginDate":"\/Date(1417237200000)\/"},
{"WeekofYear":49,"Value":96.76,"WeekBeginDate":"\/Date(1417842000000)\/"},
{"WeekofYear":50,"Value":94.50,"WeekBeginDate":"\/Date(1418446800000)\/"}
]
The dates in the JSON represent the date on each Saturday of the week in question. However, when we render the graph, it displays the date from the Sunday of the week instead, as displayed in the screenshot.
Chart Screenshot
We are using the following code in the Razor engine to generate the chart:
#(Html.Kendo().Chart<Dashboard.Models.CentralScheduling>()
.Name("CallsAnswered")
.Title("% of Calls Answered")
.Legend(legend => legend.Visible(false))
.DataSource(dataSource => dataSource
.Read(read => read.Action("CentralScheduling", "Dashboard").Data("filterStatusData")))
.Series(series =>
{
series.Line(d => d.Value)
.Tooltip(t => t.Visible(true).Template("#=value#%"));
})
.CategoryAxis(axis => axis
.Categories(model => model.WeekBeginDate) //WeekBeginDate holds the date at the end of the week for this particular chart
.Labels(labels => labels.Format("MM/dd/yyyy")
.Rotation(-60)
)
)
.ValueAxis(axis => axis
.Numeric().Labels(labels => labels.Format("{0}%"))
.Max(100)
)
.SeriesColors("#3aafff","#ffb800","#a7008f","#99c900","#FF0000", "#002060")
)
The filterStatusData function sets a flag that we use in the controller to generate the JSON for the calling chart.
I am at a loss to explain why a different date is being chosen for the chart rather than the one that we are supplying.
An option - this is comming from Telerik - is to pass the date as a string from the server instead of a .Net DateTime object. The client will parse it just like it does a date object. Use this format "yyyy-mm-dd HH:MM"
so your json would be something like:
[
{"WeekofYear":45,"Value":96.08,"WeekBeginDate":"2014-12-16 07:00"},
...

Parsing search results from website, compojure/clojure

For some time I'm working on a simple clojure project for movies, so I'm trying to parse search results from a particular web site, in my case imdb.com. Not sure If I'm on the right track for this so I'm hoping someone would help me out.
Homepage will look simple enough, with text-field where you would enter movie name and submit button named "Search". I'll try to be as much deatailed as possible:
1.This is the main page:
(defn view-input []
(view-layout
[:h2 "Find your Movie"]
[:body {:style "font: 14pt/16pt helvetica; background-color: #F2FB78; padding-top:100px; text-align: center" }
(form-to [:post "/"]
[:br]
[:br]
(text-field {:placeholder "Enter movie name" } :a) [:br]
(submit-button "Search")
)]
))
2.These are the functions that I've been using:
(defn create-flick-url [a]
(str "http://www.imdb.com/search/title?title=" a "&title_type=feature"
))
(defn flick-vec [categories a]
(vec (let [flick-url (create-flick-url a)
flick-names (print-flick-name-content flick-url)]
(mapper-gen4 flick-names
(get-image-content flick-url)
))) )
(defn view-output2 [categories a]
(view-layout
[:h2 "Search results"]
[:form {:method "post" :action "/"}
(interleave
(for [flick (flick-vec categories a)]
(label :title (:name flick)))
(for [flick-name (flick-vec categories a)]
[:br])
(for [flick-image (flick-vec categories a)]
[:img {:src (:image flick-image)}])
(for [flick (flick-vec categories a)]
[:br]))
]))
3.And this is the GET/POST part in the same class, where I'm using the view-output and view-output2 functions :
(defroutes main-routes
(GET "/" []
(view-input))
(POST "/" [categories a]
(view-output2 categories a))
4.Also, these are the functions that previous ones are using:
(defn print-flick-name-content
[url]
(vec (flatten (map :content (h3+table url)))))
(defn get-image-content
[url]
(vec (flatten (map #(re-find #"http.*jpg" %)
(map :style (map :attrs (h3+table2 url)))))))
(defn get-page
"Gets the html page from passed url"
[url]
(html/html-resource (java.net.URL. url)))
(defn h3+table
"Return seq of <h3> and table tags, where content of the <h3> tag meet defined condition"
[url]
(html/select (get-page url)
[:td (html/attr= :class "title") :h3 :a]))
(defn h3+table2
"Return seq of <h3> and table tags, where content of the <h3> tag meet defined condition"
[url]
(html/select (get-page url)
[:td (html/attr= :class "image")]))
5.And here's the last one, function defined in another class which deals with map:
(defn mapper-gen4
[names images] (sort-by :name (map #(hash-map
:name %1 :image %2) names images)))
I know it's a bit much, but this way someone will see where the problem is, so far the Search result page shows no results, nor errors, only blank page with h2 Search Results title. Thanks in advance!
I would start at the form handling route:
(POST "/" [categories a]
(view-output2 categories a))
inserting a humble print statement:
(POST "/" [categories a]
(do
(println "CAT" categories "A" a)
(view-output2 categories a)))
Make sure your handler includes wrap-reload so you can refresh the page and check the console. You might see that categories and a are nil, in which case you might next try something like this:
(POST "/" req
(do
(println "REQ" req)
(view-output2 *hard-coded-categories* *hard-coded-a*)))
Replace hard-coded-categories and hard-coded-a with the data structure you are expecting to see. This will test:
You will see in the request where the parameters are.
You will see whether your rendering code does what you expect with the right data.
If indeed the problem is that categories and a are nil, it might just be that you forgot a middleware handler (see why this matters).
If they contain the data you expect in the structure you expect, then it is time to drill down into your other functions. For this I recommend using a REPL session and calling your top level function with the hard-coded values you are expecting from the form, however if you are using wrap-reload you could also just resubmit the form. For example you could add printouts of the inputs and outputs of your mapper-gen4 function and get-page function.
Finally after playing with some values and results, copy these from your REPL into a test file so that you have some permanent assertions about how your code behaves.
If all else fails, posting a link to your github project will get you better help - or if it is private, create a minimal example project so that people can help you more precisely.

using Foreach to make a table

Im new to PHP and I made this to display to my website what has been uploaded in the fdpp portal
<?php $resp = file_get_contents("http://fdpp.blgs.gov.ph/api/documents?source=datatable&sSearch=kalinga");
$clean = json_decode($resp);
print_r($clean); ?>
this is the result :
stdClass Object
(
[iTotalRecords] => 130035
[iTotalDisplayRecords] => 879
[sEcho] => 0
[aaData] => Array
(
[0] => stdClass Object
(
[lgu] => <a href=' http://fdpp.blgs.gov.ph/documents/view/129293'>CAR<br/>Kalinga<br />Balbalan</a>
[document] => <a href=' http://fdpp.blgs.gov.ph/documents/view/129293'>Local Disaster Risk Reduction and Management Fund Utilization (LDRRMF)</a>
[period] => Quarter 1 2014
[status] => Required • SUBMITTED
[desc] => The atng.
)
[1] => stdClass Object
(
[lgu] => <a href=' http://fdpp.blgs.gov.ph/documents/view/129188'>CAR<br/>Kalinga<br />Balbalan</a>
[document] => <a href=' http://fdpp.blgs.gov.ph/documents/view/129188'>Manpower Complement</a>
[period] => Quarter 1 2014
[status] => Required • SUBMITTED
[desc] => The file ag.
)
what shall I add to my code to put this in a table with column name lgu, document, period? I tried reading foreach manual but I cant figure it out can someone help me?
I have to agree with PeeHaa (+1) with not enough information given, but I'm going to attempt to help you out.
The following assumptions were made:
You have a local MySQL DB named "testdb"
You have the PDO extension installed
In "testdb", you have a table named "test_table" with 4
columns (id, lgu, document, period)
First, you need to set the second parameter in json_decode to true to return an associative array rather than an object (PHP: json_decode).
So, based upon the limited information, here is a working version:
<?php
$resp = file_get_contents("http://fdpp.blgs.gov.ph/api/documents?source=datatable&sSearch=kalinga");
$clean = json_decode($resp,true);
// Open connection to your MySQL DB
$db = new PDO('mysql:host=localhost;dbname=testdb', 'username', 'password');
// Parse the now-associative array and insert into table
foreach($clean['aaData'] as $doc){
$stmt = $db->prepare("INSERT INTO test_table(lgu,document,period) VALUES(:lgu,:document,:period)");
$stmt->execute(array(':lgu' => $doc['lgu'], ':document' => $doc['document'], ':period' => $doc['period']));
}
?>
You should really provide some more information for a more exact answer.
But, this should set you in the right direction.

Resources