Instead of
Application("Preview").windows[0].bounds = {"x": 1440, "y":25, "width":1440, "height": 2535}
I'd like to move the window but instead of using an index, I'd like to use the window's ID. I got the ID with
Application("Preview").windows[0].id();
But when I replace the index with the ID:
Application("Preview").windows.whose({id: 15596}).bounds = {"x": 1440, "y":25, "width":1440, "height": 2535}
I get
Error -1728: Can't get object.
Related
I am trying to build a data storage for time series data, for this I have created nested objects Coin and Data, where Coin is parent object and contains Data entries that each data entry is individual object. at this moment my code creates nested object Coin[Data] as I build create function within CoinSerializer, but I could not use proper method to add/create child object within existing Coin object
In my python virtual environment I've been using django 2.1.4 drf 3.9 and python 3.6.. also as a backend db engine for my project I got mongodb and use djongo 1.2 to maintain it
Any suggested idea or way for my problem would be greatly appreciated, as its my first post ever and sorry for any Inappropriate style..
models.py
class Coin(models.Model):
coin_name = models.CharField(max_length=100,blank=True)
class Data(models.Model):
coin = models.ForeignKey(Coin, related_name='data', on_delete=models.CASCADE,blank=True)
date = models.DateField(("Date"),blank=True)
open = models.FloatField(null=True, blank=True)
high = models.FloatField(null=True, blank=True)
low = models.FloatField(null=True, blank=True)
close = models.FloatField(null=True, blank=True)
class Meta:
unique_together = ('coin', 'date',)
ordering = ['date']
def __unicode__(self):
return '%d: %d %d %d %d' % (self.date, self.open, self.high,
self.low, self.close)
serializers.py
class DataSerializer(serializers.ModelSerializer):
class Meta():
model = models.Data
fields = ('coin_id','pk','id','date','open','high','low','close')
class CoinSerializer(serializers.ModelSerializer):
data = DataSerializer(many=True)
class Meta:
model = models.Coin
fields = ('pk','id','coin_name', 'data')
def create(self, validated_data):
data = validated_data.pop('data')
coin = models.Coin.objects.create(**validated_data)
models.Data.objects.create(coin=coin, **data[0])
return coin
my result is kind of this
{
"pk": 101,
"id": 101,
"coin_name": "ripple",
"data": [
{
"coin_id": 101,
"pk": 56,
"id": 56,
"date": "2016-12-25",
"open": 4036.0,
"high": 4101.0,
"low": 3983.0,
"close": 4065.0
}
]
},
and expect to consist lots of data objects which I will add by the time in existing coin object
{
"pk": 101,
"id": 101,
"coin_name": "ripple",
"data": [
{
"coin_id": 101,
"pk": 56,
"id": 56,
"date": "2016-12-25",
"open": 4036.0,
"high": 4101.0,
"low": 3983.0,
"close": 4065.0
}
{
"coin_id": 102,
"pk": 57,
"id": 57,
"date": "2016-12-26",
"open": 4065.0,
"high": 4189.0,
"low": 3967.0,
"close": 4075.0
}
...
...
]
},
You're going about it the wrong way. You should instead make another endpoint for Data too. There you can create data and pass the id of the parent coin. Using the nested architecture is only meaningfull when you're creating both the coin and the data at the same time. In this case, just use a data endpoint to create data while passing the id of the coin
EDIT: BULK CREATE
And just to throw a little light on how to implement bulk create for several Data objects - you will need to imlement it using a loop as model.objects.create() excpects data for a single object. You could use bulk_create but it has a lot of caveats, so I would use a loop
try change your input data with more than one item in array like example:
data = [{'date': '2016-12-25', 'high': 4101.0, 'open': 0.0, 'low': 3983.0, 'close': 4065.0}, {'date': '2016-12-26', 'high': 4101.0, 'open': 0.0, 'low': 3983.0, 'close': 4065.0}]
This example have one more item in array data.
And change this line:
coin = models.Coin.objects.create(**validated_data)
models.Data.objects.create(coin=coin, **data[0])
to
coin = models.Coin.objects.create(**validated_data)
for item_data in data:
models.Data.objects.create(coin=coin, **item_data)
This will create some Data with FK is Coin created.
This is how I did it.. Inside my viewset.ModelViewSet implementation In my case.. The parent class contains a list of manyToMany objects. Im posting new objects in the manyToMany..> Creating them.. then reinserting the IDs into the post data and calling the base class. Worked out pretty simple.. and I like it's contained in the view. Im newer to Django however.. but this worked for me.
class CaseDeepViewSet(viewsets.ModelViewSet):
permission_classes = (IsAuthenticated,)
queryset = Case.objects.all().order_by('-id')
def get_serializer_class(self):
if self.request.method in ['GET']:
return CaseDeepSerializer
return CaseSerializer
def create(self, request):
print('IM here: ')
print(request.data)
case_interactions = request.data.pop('new_case_interactions')
listCreatedInteractions = []
for interaction in case_interactions:
print("interaction", interaction)
interaction['issara_staff'] = obj = IssaraUser.objects.get(pk=interaction.get('issara_staff'))
listCreatedInteractions.append(CaseInteraction.objects.create(**interaction).id)
request.data['case_interactions'] = listCreatedInteractions
return super().create(request)
I have an AmChart that I want to appear in an md-dialog. It's passed a JSON dataProvider and yet nothing appears.
dialog.tmpl.html:
<md-dialog aria-label="Project Zone Chart">
<md-toolbar>
<div class="md-toolbar-tools">
<h2>Project Zone Chart</h2>
<span flex></span>
<md-button class="md-icon-button" ng-click="closeDialog()">
<md-icon aria-label="Close dialog">close</md-icon>
</md-button>
</div>
</md-toolbar>
<md-dialog-content>
<p><div id="projZoneChart" style="width: 100%; height: auto;"></div></p>
</md-dialog-content>
</md-dialog>
controller.js:
var projZoneChartOps = {
type: "serial",
valueAxes: [{
minorGridAlpha: 0.08,
minorGridEnabled: true,
position: "top",
gridAlpha: 0,
precision: 0
}],
startDuration: 1,
graphs: [{
type: "column",
fillAlphas: 1,
lineAlpha: 0,
valueField: "value",
colorField: "color",
lineAlpha: 0
}],
rotate: true,
categoryField: "metric",
categoryAxis: {
gridPosition: "start",
parseDates: false,
gridAlpha: 0
}
};
createChart($scope.chartdata, projZoneChartOps);
function createChart(chartData, chartOps){
$scope.projZoneChart = AmCharts.makeChart("projZoneChart", chartOps);
$scope.projZoneChart.dataProvider = chartData;
However nothing appears in the dialog at all. Is there a problem with my chartOps?
Note: the chartData variable is a JSON object with two fields, startOfWeek (supposed to be the x-axis) and metric (supposed to be the y-axis)
There are a few issues/comments:
1) Why aren't you assigning the data to the chartOps object before calling makeChart?
chartOps.dataProvider = chartData;
$scope.projZoneChart = AmCharts.makeChart("projZoneChart", chartOps);
This will actually make the chart start off with your data. The way you're doing it will require that you call validateData() on your chart object after manually setting the dataProvider, which is unnecessary overhead compared to including it directly in makeChart.
$scope.projZoneChart = AmCharts.makeChart("projZoneChart", chartOps);
$scope.projZoneChart.dataProvider = chartData;
$scope.projZoneChart.validateData(); //required if you're doing it this way but unneccessary overhead compared to simply including it inside of makeChart directly as you're essentially remaking the chart after you create it for the sake of rendering your data.
2) Make sure your *field properties match. startOfWeek isn't mentioned in your chart config at all, even though you're saying it's in your JSON data. Your valueField is set to "value" - you might want to set it to "startOfWeek" instead unless you're modifying your JSON object somewhere else.
3) Displaying charts inside a modal or other dynamic/hidden elements typically require that you call the chart object's invalidateSize method when the modal/tab/etc containing the chart is visible so that it will render correctly. You'll want to check for whatever event md-dialog offers to determine when it is visible before calling $scope.projZoneChart.invalidateSize().
I have a situation similar to the example shown in http://c3js.org/samples/data_json.html My simple intention is to get the name of the row (i.e. 'www.site1.com') into the tooltip header. My problem: I cannot find it in the d-values.
Can anyone help?
You cannot find it in d-values, because it's not a value actually - it's a category.
Have a look at Category Axis example, maybe it helps you:
var chart = c3.generate({
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250, 50, 100, 250]
]
},
axis: {
x: {
type: 'category',
categories: ['cat1', 'cat2', 'cat3', 'cat4', 'cat5', 'cat6', 'cat7', 'cat8', 'cat9']
}
}
});
I solved it by using the d-value to address the right category of my JSON, or rather the array in my JSON. (Seemed more complicated since I load the data after I create the chart.)
I'd like to create a Resource Gantt with AnyGantt, currently, when mouse pointer move to the task, it show the resource name and starttime/endtime. I would like to show task name and starttime/endtime.(with following data, I would like to show "task1", not "Equipment#1")
Anyone can help?
Thanks!
[ {"id": 13, "name": "Equipment#1", "periods": [{"id": "task1", "end": 1494099000000, "fill": "green", "start": 1494055800000}]}]
First of all, period's ID is required field and must be unique for gantt chart live edit purposes. You can set any custom field in your raw data like this:
var rawdata = [{
id: 13,
name: "Equipment#1",
periods: [
{
id: "task1",
start: Date.UTC(2017, 4, 6),
end: Date.UTC(2017, 4, 7),
periodCustomName: "Task 1" //This value will be used in tooltip's title.
}
]
}];
Since the data is ready, you have to set custom title format for timeline's tooltip:
//Getting gantt chart's timeline to work with its tooltip.
var timeline = chart.getTimeline();
//Gettnig timeline's tooltip.
var tlTooltip = timeline.tooltip();
//Setting tooltip title format function to access your custom raw data field.
tlTooltip.titleFormat(function() {
//If period is hovered.
if (this.period) {
//Return periodCustomName-field if specified.
return this.period.periodCustomName || this.getData('name');
}
//Else return name of data item ("Equipment#1")
return this.getData('name');
});
I'm trying to swap out data sets in a C3.js graph.
The code I assumed would work based on the C3 docs looks like this:
chart.unload();
chart.load({
columns: [
['data3', 100, 90, 80, 70, 60, 50]
]
});
But this doesn't work. You'll notice that the graph rendered on the following Plunkr renders improperly, so I'm clearly doing something wrong: https://jsfiddle.net/7rfm9om9/
What is the idiomatic way to replace data in a C3 chart?
Ah, it appears that chart.unload() does some asynchronous work that, if you call chart.load() immediately after in a synchronous fashion, will break the graph.
I got this working by loading the new data in a function passed to chart.unload's done callback.
chart.unload({
done: function() {
chart.load({
columns: [
['data3', 100, 90, 80, 70, 60, 50]
]
});
}
});
Working fiddle: https://jsfiddle.net/1g5v1s24/1/
According to the c3 documentation, the way to do this is to use the unload param of the load function.
chart.load({
unload: true,
columns: ['data1', 100]
});
There are issues with rendering and animations otherwise when trying to use .unload() and then .load().
This note is included in the .unload() documentation:
http://c3js.org/reference.html#api-unload
Note: If you call [the] load API soon after/before unload, unload
param of load should be used. Otherwise chart will not be rendered
properly because of [cancelation] of animation.
done will be called after data loaded, but it's not after rendering.
It's because rendering will finish after some transition and there is
some time lag between loading and rendering.
According to the documentation for .load():
http://c3js.org/reference.html#api-load
If unload given, data will be unloaded before loading new data. If
true given, all of data will be unloaded. If target ids given as
String or Array, specified targets will be unloaded.
Note: unload should be used if some data needs to be unloaded
simultaneously. If you call unload API soon after/before load instead
of unload param, chart will not be rendered properly because of cancel
of animation.
Format would be along the lines of the following snippets:
All Data
chart.load({
unload: true,
columns: [
['data3', 100, 90, 80, 70, 60, 50]
]
});
Specified Targets
chart.load({
unload: ['data1', 'data2'],
columns: [
['data3', 100, 90, 80, 70, 60, 50]
]
});
JSFiddle:
https://jsfiddle.net/d8g015n2/