# Use a function that creates a DateListPlot and works in TabView?

Posted 2 years ago
2821 Views
|
7 Replies
|
0 Total Likes
|
 I am working on building a repository that would allow organizations to track energy consumption over time for multiple buildings. I have created an EntityStore where the buildings are the registered entities. Each building's data is stored in a Databin. I am trying to create a page where each building's data can be viewed as a DateListPlot. I created a function that returns a DateListPlot of a specific building's utility bills.The structure of the data in the Databin is: The DateListPlot function is: campusBuldingMonthlyBills[campusbuilding_] := DateListPlot[ TimeSeries@ Map[{#["DATE"], #["KWH"]} &, Normal[Dataset[ EntityValue[Entity["Campus Building", campusbuilding], "monthly bills"]]]]] The function works well when used alone. Unfortunately, when I use the function within TabView an error is occuring, and I can't figure it out why. Here is my TabView code. TabView[Row[{Rasterize[ Show[EntityValue[#, "image"], ImageSize -> {40, 40}], Background -> None], #}] -> campusBuldingMonthlyBills[#] & /@ EntityList["Campus Building"], ControlPlacement -> Left] Here is a copy of one of the error messages:  DateListPlot::ldata: TimeSeries[EntityValue[{ Entity[Campus Building,weld][DATE], Entity[Campus Building,weld][KWH]}, {monthly bills[DATE],monthly bills[KWH]}]] is not a valid dataset or list of datasets. Here is what the output of the TabView looks like: I'm clearly missing something, but I'm not seeing why my code isn't working. If anyone has any insight I would greatly appreciate it!Thank you, Kyle MacLaury
7 Replies
Sort By:
Posted 2 years ago
 Kyle,I cannot really try, because I do not have your data, but maybe when you write your code in a more "step by step" manner, I cannot see why things should not work, e.g.: ri = ImageResize[#, {40, 40}] &@*ExampleData /@ {{"TestImage", "Girl"}, {"TestImage", "Girl2"}, {"TestImage", "Girl3"}, {"TestImage", "Lena"}, {"TestImage", "Tiffany"}, {"TestImage", "Mandrill"}}; data = Table[{DateObject@RandomInteger[{0, UnixTime[]}], RandomInteger[100]}, {r, 6}, {c, 10}]; dlpl = DateListPlot /@ data; TabView[MapThread[Rule, {ri, dlpl}]] BTW: Nice idea to use images as tab labels! Regards -- Henrik
Posted 2 years ago
 Thank you, Henrik. I played around with your idea a bit, but Im still struggling. I think it has something to do with TabView. I tried this with another function that also works independently, but doesnt work within the context of TabView.
Posted 2 years ago
 Hi Kyle,What does this evaluate to? campusBuldingMonthlyBills[#] & /@ EntityList["Campus Building"] 
Posted 2 years ago
 Rohit, Thank you, that was a helpful suggestion. I still haven't fully pieced it together, but here is what I've figured out so far. Below I pasted what you suggested before I defined the function, and then after I defined the function. The code did what I expected before I defined the function.After I define the function some unexpected things happen. The code does seem to be ignoring the Normal[Dataset[ piece of the function, and I'm seeing Entity["Campus Building" repeated in the output, which I don't understand. I think I may need to figure out another way to define my function to work around these issues. In[5]:= campusBuildingMonthlyBills[#] & /@ EntityList["Campus Building"] Out[5]= {campusBuildingMonthlyBills[ Entity["Campus Building", "weld"]], campusBuildingMonthlyBills[Entity["Campus Building", "chapel"]], campusBuildingMonthlyBills[Entity["Campus Building", "barton"]], campusBuildingMonthlyBills[Entity["Campus Building", "bean"]], campusBuildingMonthlyBills[Entity["Campus Building", "bio shelter"]], campusBuildingMonthlyBills[Entity["Campus Building", "test"]]} In[9]:= campusBuildingMonthlyBills[#] & /@ EntityList["Campus Building"] During evaluation of In[9]:= DateListPlot::ldata: TimeSeries[Entity[Campus Building,weld][{monthly bills[DATE],monthly bills[KWH]}]] is not a valid dataset or list of datasets. During evaluation of In[9]:= DateListPlot::ldata: TimeSeries[Entity[Campus Building,chapel][{monthly bills[DATE],monthly bills[KWH]}]] is not a valid dataset or list of datasets. During evaluation of In[9]:= DateListPlot::ldata: TimeSeries[Entity[Campus Building,barton][{monthly bills[DATE],monthly bills[KWH]}]] is not a valid dataset or list of datasets. During evaluation of In[9]:= General::stop: Further output of DateListPlot::ldata will be suppressed during this calculation. Out[9]= {DateListPlot[ TimeSeries[ Entity["Campus Building", Entity["Campus Building", "weld"]][{"monthly bills"["DATE"], "monthly bills"["KWH"]}]]], DateListPlot[ TimeSeries[ Entity["Campus Building", Entity["Campus Building", "chapel"]][{"monthly bills"["DATE"], "monthly bills"["KWH"]}]]], DateListPlot[ TimeSeries[ Entity["Campus Building", Entity["Campus Building", "barton"]][{"monthly bills"["DATE"], "monthly bills"["KWH"]}]]], DateListPlot[ TimeSeries[ Entity["Campus Building", Entity["Campus Building", "bean"]][{"monthly bills"["DATE"], "monthly bills"["KWH"]}]]], DateListPlot[ TimeSeries[ Entity["Campus Building", Entity["Campus Building", "bio shelter"]][{"monthly bills"[ "DATE"], "monthly bills"["KWH"]}]]], DateListPlot[ TimeSeries[ Entity["Campus Building", Entity["Campus Building", "test"]][{"monthly bills"["DATE"], "monthly bills"["KWH"]}]]]} 
Posted 2 years ago
 Well, exactly this was the idea in my reply above: Doing it step by step! create a list of images create a list of DateListPlot create the TabView Then it most likely will become obvious where the problem is. Why is this so difficult?
 You are passing an Entity to campusBuildingMonthlyBills as the campusbuilding argument, which passes it to EntityValue[Entity["Campus Building", campusbuilding],. That is where the nested Entity calls are coming from. You have coded campusBuildingMonthlyBills to take the name of a building, but you are passing it an Entity.Follow Henrik's great advice.
 Rohit and Henrik,Thank you both! Your advice was quite helpful.Here is where I ended. databintoTimeSeries[databin_Databin] := DateListPlot[ TimeSeries@Map[{#["DATE"], #["KWH"]} &, Normal[Dataset[databin]]]] TabView[Row[{Rasterize[ Show[EntityValue[#, "image"], ImageSize -> {40, 40}], Background -> None], #}] -> databintoTimeSeries[EntityValue[#, "monthly bills"]] & /@ EntityList["Campus Building"], ControlPlacement -> Left] Everything outputs as expected now.