Daily subsets of Annual Data - subset

I am trying to optimize an energy production process in a year, based on the hourly resolutions. The purchased electricity price from the grid has two different values based on the two times of a day; between 07:00-18:00 the price is 10, between 18:00-07:00 the price is 5.
The time sets are:
P_el electricityprice /t7*t18 10, t19*t6 5, ....../
t time /t1*t8760/
How can I create the P_el automatically, so that I don't need to write different sets by hand until the 8760th hour?

I think what you want to do here is make p_el a parameter, not a set. The following should work. (Do check that I got the timing exactly right)
set t "time" /t1*t8760/;
parameter hour(t) "hour of the day from 1 to 24";
parameter p_el(t) "electricity price";
hour(t) = mod(ord(t), 24);
p_el(t) = 5;
p_el(t)$(hour(t) >= 7 and hour(t) < 18) = 10;

Related

Revit API changes wall parameters: from metadata it showed the correct result, not reflected in UI however

Using revit-python-wrapper to create Wall then adjust the Wall height and Wall offset to the ground.
Here is the code
from rpw import db
from rpw import DB
start_point = XYZ(0, 0, 0)
end_point = XYZ(45, 0, 0)
# Wrapper Line
line = Line.new(start_point, end_point)
levels = db.Collector(of_class='Level')
level_0 = levels.get_first()
wall = DB.Wall.Create(doc, line.unwrap(), level_0.Id, False)
w = db.Wall(wall)
w.parameters['Unconnected Height'].value = 2675
w.parameters['Base Offset'].value = 45
Wall created successfully in the empty Revit project.
Using snoop revit DB, only one wall is found. The ID is : 318835
Checked the parameters belonging to this Wall - 318835. The parameter 'Unconnected Height' has correct double value: 2675.0 and the parameter "Base Offset" has correct double value: 45.0.
So far, everthing is perfect and per my expectation.
But, from the UI interface, the only Wall created is shown in wrong position. In 3D view, it's above the Level 1 which height is 4000.
And from the proporty tab of the selected Wall, the two parameters are also in the wrong values.
'Unconnected Height' has correct double value: 815340.0 and the parameter "Base Offset" has correct double value: 13716.0.
When I digged into deeper, I found actually the value I changed is shown in AsDouble. However, the value I changed in the UI is shown AsValueString. Both of them are pointing to the same property. However they are different, my understanding they should be the same value but in different data format.
Am I wrong?
I figured it out now.
Internally, Revit use feet rather than mm.
So, make sure convert the mm to feet then pass it to value.
w.parameters['Unconnected Height'].value = mm_to_feet(2675)
w.parameters['Base Offset'].value = mm_to_feet(45)

Count based on two sub groups in Power Bi

I have Data as in following table, I want to show the % of work order count over the year for each group in stacked area chart but I am struggling to get the correct %. From the below data the % of each Days Delayed group should come as 50%
Appreciate any helps.
First, create this below Measure-
group_wsie_percentage =
VAR total_count =
CALCULATE(
COUNT(your_table_name[days delayed group]),
ALLEXCEPT(
your_table_name,
your_table_name[year]
)
)
VAR total_group_count =
CALCULATE(
COUNT(your_table_name[days delayed group]),
ALLEXCEPT(
your_table_name,
your_table_name[year],
your_table_name[days delayed group]
)
)
RETURN total_group_count/total_count
Now change the type of measure as % and configure your Stacked (I used Stacked Bar chart) chart as below-
Here is the output-

How does d3.js decides how many and which ticks to show?

On my chart, I have a time scale xAxis. I want user can do zoom in, zoom out operations to switch among month view(display ticks of one month), week view( display ticks of a week, Mon, Tue, Wed ...), day view( display ticks of 24 hours).
When I call the zoom behavior on svg. My chart is stretching and condensing nicely. But the ticks on the xAxis are changing "gradually" which is not what I want. E.g. when I zoom in at a certain scale, the ticks are [May 3, May 5, May 7 ......], the ticks D3 decides randomly seem to be skipping one day. And it will happen when user zoom further into hours as well.
What I want is: Assume that user is initially on the month view(which displays ticks of one month), then user keeps zooming in till to a certain scale, the ticks of xAxis will turn into 7 days( Mon, Tue, Wed ...... ), if user keeps zooming in, at a certain scale, the ticks turn into hours. I don't want d3 to decide ticks randomly.
How can I achieve that?
For each zoom scale you should set axis.ticks() and axis.tickFormat() explicitly.
When zoom event occurs you can call something like this:
adjustTimeAxis: function() {
switch(this.getZoomState()) {
case 'longDays':
this.axis
.ticks(d3.time.days, 1)
.tickFormat(function(d) { return d3.time.format('%a %e')(d); })
.tickSubdivide(false);
break;
case 'shortDays':
this.axis
.ticks(d3.time.days, 1)
.tickFormat(function(d) { return d3.time.format('%e')(d); })
.tickSubdivide(false);
break;
case 'weeks':
this.axis
.ticks(d3.time.mondays, 1)
.tickFormat(null)
.tickSubdivide(6);
break;
default: // months
this.axis
.ticks(d3.time.months, 1)
.tickFormat(null)
.tickSubdivide(1);
}
} // adjustTimeAxis
In this code function this.getZoomState returns one of the string values ['longDays', 'shortDays', 'weeks'] depending on zoom scale.
You can see how this code works here: http://bl.ocks.org/oluckyman/6199145

jQuery Flot: Change xaxis when zooming

Is there a way I can get the x-axis to switch from showing hour, to e.g. week days, months .. when zooming out?
Currently my x-axis is configured as such:
xaxis: {
mode: "time",
minTickSize: [1, "second"],
timeformat: "%H:%M:%S",
}
My default the graph looks nice, but when I zoom out enough times, the labels on the xaxis just display "00:00". How can I change the timeformat so that the date is included also? E.g. Tue 27 00:00 or similar.
Here's an example of when the graph is zoomed out a lot (obviously I need to remote some datapoints to make it look smoother..)
You can add a date using the standard specifiers, like %Y-%m-%d. A full list can be found in the API docs under the Time Series Data section.
To get the format to update based on the range, i.e. show HMS when zoomed in but YMD when zoomed out, is trickier. You'll need to listen for the 'plotzoom' event and check the range to see whether the format needs to change. If so, use getOptions() to retrieve and update the plot's options, then call setupGrid & draw to redraw the plot using the new format.
I solved this by making a custom tickFormatter for the X-axis:
In your xaxis options put:
xaxis: {
mode: "time",
tickFormatter: customXAxisFormatter,
...
}
Then your customXAxisFormatter could be eg. :
function customXAxisFormatter(val, axis)
{
var d = new Date(val);
// If time difference is more than 24 hours
if ((axis.max - axis.min) > (24*3600*1000))
return d.strftime("%a<br>%H:%M");
else
return d.strftime("%H:%M");
}
I hope this helps :)

Detect all available scanner resolutions using WIA

How can I programmatically detect all available resolutions (in dpi) for a specified scanner using WIA 2.0? What about page sizes supported? Any ideas?
Pseudo code:
Assume you have device info, connect to it:
var device = deviceInfo.Connect();
if device is not null….. then you can get the Item
Note that items begin at index 1 for device items
Item item = device.Items[1];
An Item has various properties which you can enumerate
e.g.
foreach (Property prop in item.Properties)
{
var temp = prop.Name + " " + prop.PropertyID + " " + prop.get_Value();
}
In this case to find Maximum DPI supported by your scanner you could use.
"Horizontal Optical Resolution" (property id: 3090)
"Vertical Optical Resolution" property id: 3091
.. However if you examine the properties enumeration you will see there is nothing to tell you the minimum or list of all available DPI settings.
.. Now I could not find anything either….
However I did find a way of discovering the minimum DPI…
You may be aware of WIA intent, the enumeration allows you to set scanning type e.g. colour, grey scale etc. (property id: 6146)
var currentIntent = item.Properties.get_Item("6146");
// set to colour
currentIntent.set_Value(WiaImageIntent.ColorIntent);
.. However you can also set WIA image bias in this way (to either maximum quality or minimum size)
This is not via image intent enumeration but is done by OR ing the appropriate values
// set minimum size as WIA bias
var intent = (int)item.Properties.get_Item("6146").get_Value();
item.Properties.get_Item("6146").set_Value(intent | 0x00010000);
http://msdn.microsoft.com/en-us/library/ms630190%28v=vs.85%29.aspx
And if you now look at the DPI (assuming previously DOI was not actually at minimum)
var dpiHorizontal = item.Properties.get_Item("6147").get_Value();
var dpiVertical = item.Properties.get_Item("6148").get_Value();
.. you should see that DPI is now set to it’s lowest (to give minimum size scan)
A big warning.
As soon as you set bias (be it minimum size or maximum quality) any previous DPI values you set are changed (as are various other properties for image dimensions etc – it makes wide ranging changes).
.. So, if you want to stay in control I suggest just finding minimum dpi once and storing it in configuration – Or if you do it each time, discard that item (after getting minimum DPI) and use a new item with no bias set.
.. So you now have max and min DPI values – how to get a list?
.. Again I know of no way .. but
You could have a list of “sensible DPI values”
e.g. 75, 100, 150, 200, 300, 600, 1200, 2400
As (depending on scanner resolution) these are “popular” values to support
.. Depending on your max / min DPI values you know what “popular” values may be worth trying.
.. and when setting DPI do it via try / catch
e.g.
try
{
item.Properties.get_Item("6147").set_Value(myDPI); // horizontal DPI
item.Properties.get_Item("6148").set_Value(myDPI); // vertical DPI
}
catch
{
// not supported so have some logic where try a different “popular” value
}
I see this type of issue with one scanner I use – just because a DPI is within the max / min limits does not mean it is supported.
Although many scanners WIA drivers support 100, 100 DPI, this one does not but does provide 75,75 DPI or 150,150 DPI
This approach is nasty and kludgy but works (and again you could just do this once, run through your list of popular “DPI” values, try and set them, and be left with a list of which DPI settings your scanner supports.
For the sake of simplicity sake these pseudocode examples assume vertical & horizontal DPI may both be set to same value .. this may not be the case with all scanners!
You can use the SubTypeMin and SubTypeMax properties of WIA_IPS_XRES and WIA_IPS_YRES to get the allowed resolution ranges. You can probably use something similar to determine which page sizes are supported.
WIA.Property horizontalResolutionProperty = FindProperty(_scannerDevice.Items[1].Properties, HORIZONTAL_RESOLUTION);
if (horizontalResolutionProperty != null)
{
// SubTypeMin and SubTypeMax are subproperties that tell what the min and max values are for the given property
if (horizontalResolutionProperty.SubTypeMin > minResolution) minResolution = horizontalResolutionProperty.SubTypeMin;
if (horizontalResolutionProperty.SubTypeMax < maxResolution) maxResolution = horizontalResolutionProperty.SubTypeMax;
}
WIA.Property verticalResolutionProperty = FindProperty(_scannerDevice.Items[1].Properties, VERTICAL_RESOLUTION);
if (verticalResolutionProperty != null)
{
// SubTypeMin and SubTypeMax are subproperties that tell what the min and max values are for the given property
if (verticalResolutionProperty.SubTypeMin > minResolution) minResolution = verticalResolutionProperty.SubTypeMin;
if (verticalResolutionProperty.SubTypeMax < maxResolution) maxResolution = verticalResolutionProperty.SubTypeMax;
}
The horizontal and vertical resolution properties have a Subtype property which, depending on it's value, let you acces the allowed value or values for the resolution:
var xResolutionProperty = item.Properties["Horizontal Resolution"];
switch (xResolutionProperty.SubType)
{
case WIASubType.ListSubType:
// Here you can access property SubTypeValues, which contains a list of allowed values for the resolution.
break;
case WIASubType.RangeSubTypes:
// Here you can access SubTypeMin and SubTypeMax properties, with the minimum and maximum allowed values.
break;
case WIASubType.UnspecifiedSubType:
// Here you can access SubTypeDefault property, which contains the default resolution value.
break;
}

Resources