I need to find the 20 most views videos between two times, i did this:
$Param['body']='
{
"query" : {
"match_all" : {}
},
"facets" : {
"WhatIwant" : {
"range" : {
"key_field" : "time",
"value_field" : "video_id",
"ranges" : [
{ "from" :1399236597 , "to" : 1400331247 }
]
}
}
}
}';
I get a result where i can see some params, but i don't have the entire list look:
[facets] => Array
(
[WhatIwant] => Array
(
[_type] => range
[ranges] => Array
(
[0] => Array
(
[from] => 1400331247
[count] => 4585
[min] => -1
[max] => 3584
[total_count] => 4585
[total] => 12884198
[mean] => 2810.0758996728
)
)
)
)
)
I want something like this if it's possible :
[facets] => Array
(
[WhatIwant] => Array
(
[_type] => range
[ranges] => Array
(
[0] => Array
(
[time] => 1400331247
[video_id] => 4585
)
[1] => Array
(
[time] => 1400331248
[video_id] => 4582
)
[2] =>Array()
.....
....
[19]
)
)
)
)
Thanks for reading me
You just need a simple term facet, grouped by video_id with applied range filter
Related
this query is perfectly working in mysql & return only one row.
SELECT * FROM `civil_service_mileage_rates` WHERE `min_distance` <400
and `max_distance` >400 and `min_capacity`<1300 and `max_capacity`>1300
But when i tried the same in cakephp3 , it return many rows data instead of one.
cakephp3 code:
$civilserviceMileageTable = TableRegistry::get('civil_service_mileage_rates');
$mileagedata = $civilserviceMileageTable->find('all');
$claimAmount = $mileagedata->where(['min_distance'<400
and 'max_distance'>400 and 'min_capacity'<1300 and 'max_capacity'>1300]);
please help..thanks in advance
Updated:
output of above code
"data": [
{
"id": 1,
"band": "Band 1",
"min_distance": "0",
"max_distance": "1500",
"min_capacity": "0",
"max_capacity": "1200",
"claim_amount": 37.95
},
{
"id": 2,
"band": "Band 1",
"min_distance": "0",
"max_distance": "1500",
"min_capacity": "1201",
"max_capacity": "1500",
"claim_amount": 39.86
},
{
"id": 3,
"band": "Band 1",
"min_distance": "0",
"max_distance": "1500",
"min_capacity": "1501",
"max_capacity": "2500",
"claim_amount": 44.79
}
Though, it should have display only one row.
"data": [
{
"id": 2,
"band": "Band 1",
"min_distance": "0",
"max_distance": "1500",
"min_capacity": "1201",
"max_capacity": "1500",
"claim_amount": 39.86
}
}
updated :
after print the array details, i got the result.
Array
(
[0] => Cake\ORM\Entity Object
(
[id] => 1
[band] => Band 1
[min_distance] => 0
[max_distance] => 1500
[min_capacity] => 0
[max_capacity] => 1200
[claim_amount] => 37.95
[[new]] =>
[[accessible]] => Array
(
[*] => 1
)
[[dirty]] => Array
(
)
[[original]] => Array
(
)
[[virtual]] => Array
(
)
[[errors]] => Array
(
)
[[invalid]] => Array
(
)
[[repository]] => civil_service_mileage_rates
)
[1] => Cake\ORM\Entity Object
(
[id] => 2
[band] => Band 1
[min_distance] => 0
[max_distance] => 1500
[min_capacity] => 1201
[max_capacity] => 1500
[claim_amount] => 39.86
[[new]] =>
[[accessible]] => Array
(
[*] => 1
)
[[dirty]] => Array
(
)
[[original]] => Array
(
)
[[virtual]] => Array
(
)
[[errors]] => Array
(
)
[[invalid]] => Array
(
)
[[repository]] => civil_service_mileage_rates
)
[2] => Cake\ORM\Entity Object
(
[id] => 3
[band] => Band 1
[min_distance] => 0
[max_distance] => 1500
[min_capacity] => 1501
[max_capacity] => 2500
[claim_amount] => 44.79
[[new]] =>
[[accessible]] => Array
(
[*] => 1
)
[[dirty]] => Array
(
)
[[original]] => Array
(
)
[[virtual]] => Array
(
)
[[errors]] => Array
(
)
[[invalid]] => Array
(
)
[[repository]] => civil_service_mileage_rates
)
)
try this
$this->civil_service_mileage_rates = TableRegistry::get('civil_service_mileage_rates');
$this->civil_service_mileage_rates->find('all')
->where([
'min_distance <' => 400,
'max_distance >' => 400,
'min_capacity <' => 1300,
'max_capacity >' => 1300,
]);
$result = $this->civil_service_mileage_rates->toArray();
Try this one hope it will solve your problem.
$civilserviceMileageTable = TableRegistry::get('civil_service_mileage_rates');
$mileagedata = $civilserviceMileageTable->find();
$mileagedata->where(['min_distance <'=> 400]);
$mileagedata->where(['max_distance >' => 400]);
$mileagedata->where(['min_capacity <' => 1300]);
$mileagedata->where(['max_capacity >' => 1300]);
$claimAmount = $mileagedata->toArray();
In controller i have:
return response()->json(
[
'number' => (float)8
],
Response::HTTP_OK,
[],
JSON_PRESERVE_ZERO_FRACTION
);
This is output:
{
"number": 8
}
Is it possible to get 8.0?
This working good:
json_encode(['number' => (float)8],JSON_PRESERVE_ZERO_FRACTION);
UPDATE:
when i set response()->json from above to $variable and then print_r($variable) i get this:
(so it looks like it working, but with return in browser i get still 8 not 8.0)
Illuminate\Http\JsonResponse Object
(
[data:protected] => {"number":8.0}
[callback:protected] =>
[encodingOptions:protected] => 1024
[headers] => Symfony\Component\HttpFoundation\ResponseHeaderBag Object
(
[computedCacheControl:protected] => Array
(
[no-cache] => 1
[private] => 1
)
[cookies:protected] => Array
(
)
[headerNames:protected] => Array
(
[cache-control] => Cache-Control
[date] => Date
[content-type] => Content-Type
)
[headers:protected] => Array
(
[cache-control] => Array
(
[0] => no-cache, private
)
[date] => Array
(
[0] => Thu, 08 Feb 2018 11:27:34 GMT
)
[content-type] => Array
(
[0] => application/json
)
)
[cacheControl:protected] => Array
(
)
)
[content:protected] => {"number":8.0}
[version:protected] => 1.0
[statusCode:protected] => 200
[statusText:protected] => OK
[charset:protected] =>
[original] => Array
(
[number] => 8
)
[exception] =>
)
Use number_format():
json_encode(['number' => number_format(8, 1)]);
If number is coming as a string, use (float)$stringNumber instead of $stringNumber
Problem
I made a request to Facebook's Ad Set API attempting to create an ad set with the following JSON blob, and the error I received was "Your Budget Is Too Low. The minimum budget for this ad set is $32.04."
The ad set is set to use auto_bid and a valid lifetime_target. The ad set runs for 31 days, and with a $1 minimum daily budget, setting $64 for lifetime budget should've been sufficient.
Attempted Solutions
I tried to set a higher lifetime budget: from 64 to 1000 to 5000. 1000 did not work in this case, but 5000 did.
JSON Blob Used
Array
(
[account_id] =>
[adset_schedule] =>
[bid_amount] =>
[billing_event] => IMPRESSIONS
[budget_remaining] =>
[campaign_id] => 6054825216096
[created_time] =>
[creative_sequence] =>
[daily_budget] =>
[end_time] => 2016-11-08T07:59:59+0000
[id] =>
[is_autobid] => 1
[lifetime_budget] => 64
[lifetime_imps] =>
[name] => Some-Test-Campaign
[optimization_goal] => LINK_CLICKS
[pacing_type] =>
[recommendations] =>
[rf_prediction_id] =>
[start_time] => 2016-10-07T07:00:00+0000
[updated_time] =>
[targeting] => FacebookAds\Object\TargetingSpecs Object
(
[data:protected] => Array
(
[genders] =>
[age_min] =>
[age_max] =>
[geo_locations] => Array
(
[zips] => Array
(
[0] => Array
(
[key] => US:98004
)
[1] => Array
(
[key] => US:98005
)
[2] => Array
(
[key] => US:98006
)
[3] => Array
(
[key] => US:98007
)
[4] => Array
(
[key] => US:98008
)
[5] => Array
(
[key] => US:98009
)
[6] => Array
(
[key] => US:98011
)
[7] => Array
(
[key] => US:98014
)
[8] => Array
(
[key] => US:98015
)
[9] => Array
(
[key] => US:98019
)
[10] => Array
(
[key] => US:98021
)
)
)
[geo_markets] =>
[excluded_geo_locations] => Array
(
[countries] => Array
(
)
)
[exclusions] =>
[user_adclusters] =>
[interests] =>
[user_os] =>
[user_device] =>
[wireless_carrier] =>
[page_types] => Array
(
[0] => desktopfeed
[1] => mobilefeed
[2] => mobileexternal
[3] => rightcolumn
)
[connections] =>
[excluded_connections] =>
[family_statuses] =>
[friends_of_connections] =>
[flexible_spec] => Array
(
[0] => Array
(
[interests] => Array
(
[0] => Array
(
[id] => 6003277229371
)
)
[behaviors] => Array
(
[0] => Array
(
[id] => 6017447625983
)
)
)
)
[behaviors] =>
[relationship_statuses] =>
[interested_in] =>
[life_events] =>
[location_types] =>
[politics] =>
[markets] =>
[industries] =>
[income] =>
[net_worth] =>
[home_type] =>
[home_ownership] =>
[home_value] =>
[ethnic_affinity] =>
[generation] =>
[household_composition] =>
[moms] =>
[office_type] =>
[education_schools] =>
[education_statuses] =>
[college_years] =>
[education_majors] =>
[work_employers] =>
[work_positions] =>
[locales] =>
[zips] =>
[custom_audiences] =>
[custom_locations] =>
[excluded_custom_audiences] =>
[dynamic_audience_ids] =>
[product_audience_specs] =>
[excluded_product_audience_specs] =>
)
)
[promoted_object] =>
[adlabels] =>
[product_ad_behavior] =>
[execution_options] =>
[configured_status] =>
[effective_status] =>
)
I shortened the targeting for simplicity sake, but there's over 100 postal codes being targetd.
The solution here is that lifetime_budget is denoted in cents, so $64 should be 6400.
You may check if the budget you set is not less of required.
Perform this check at the endpoint:
https://graph.facebook.com/v2.12/act_{ads_account_id}/minimum_budgets
With headers:
Authorization: Bearer {your token with 'ads_management' rights to this account}
Returns:
{
"data": [
{
"currency": "AED",
"min_daily_budget_imp": 300,
"min_daily_budget_video_views": 300,
"min_daily_budget_high_freq": 750,
"min_daily_budget_low_freq": 6000
},
{
"currency": "ARS",
"min_daily_budget_imp": 400,
"min_daily_budget_video_views": 400,
"min_daily_budget_high_freq": 1000,
"min_daily_budget_low_freq": 8000
}
]
}
PS. I see, that my response is 2 years late, but someone may find it useful.
I have following code:
$yt_profiles = $youtube->channels->listChannels('brandingSettings', array(
'mine' => 'true',
));
That returns the following output:
Google_Service_YouTube_ChannelListResponse Object
(
[collection_key:protected] => items
[etag] => "WFPuK6TsnblcGPcnMex79s42ynQ/sTnuE1bHO-tokx_mFFDt1ybN90g"
[eventId] =>
[itemsType:protected] => Google_Service_YouTube_Channel
[itemsDataType:protected] => array
[kind] => youtube#channelListResponse
[nextPageToken] =>
[pageInfoType:protected] => Google_Service_YouTube_PageInfo
[pageInfoDataType:protected] =>
[prevPageToken] =>
[tokenPaginationType:protected] => Google_Service_YouTube_TokenPagination
[tokenPaginationDataType:protected] =>
[visitorId] =>
[modelData:protected] => Array
(
[pageInfo] => Array
(
[totalResults] => 1
[resultsPerPage] => 1
)
[items] => Array
(
[0] => Array
(
[kind] => youtube#channel
[etag] => "WFPuK6TsnblcGPcnMex79s42ynQ/ecOcHFmWyWQ7ToCD7-B1L36b4L4"
[id] => UCQO6uXy5maTpYvSa_yM--Bw
[brandingSettings] => Array
(
[channel] => Array
(
[title] => Vasim Padhiyar
[showRelatedChannels] => 1
[featuredChannelsTitle] => Featured Channels
[featuredChannelsUrls] => Array
(
[0] => UCw-TnDmYDQyjnZ5qpVWUsSA
)
[profileColor] => #000000
)
[image] => Array
(
[bannerImageUrl] => http://s.ytimg.com/yts/img/channels/c4/default_banner-vfl7DRgTn.png
)
[hints] => Array
(
[0] => Array
(
[property] => channel.featured_tab.template.string
[value] => Everything
)
[1] => Array
(
[property] => channel.banner.image_height.int
[value] => 0
)
[2] => Array
(
[property] => channel.modules.show_comments.bool
[value] => True
)
)
)
)
)
)
[processed:protected] => Array
(
)
)
I want to loop through modelData:protected variable to get the list of channels and its items data. Its json object so $yt_profiles->modelData:protected not working while accessing. Please help me to solve this issue.
Thanks in advance
You can reach it as in an array:
print_r ($yt_profiles['modelData']);
Your request:
$yt_profiles = $youtube->channels->listChannels('brandingSettings', array(
'mine' => 'true',
));
To acces to values Channel title for example:
$titleChannel = $yt_profiles["items"][0]["brandingSettings"]["channel"]["title"];
To acces to values bannerImageUrl for example:
$banner = $yt_profiles["items"][0]["brandingSettings"]["image"]["bannerImageUrl"];
Does this help you?
$yt_profiles = $youtube->channels->listChannels('id, brandingSettings', array('mine' => 'true',));
foreach ($yt_profiles['modelData']['items'] as $searchResult) {
switch ($searchResult['kind']) {
case 'youtube#channel':
$channels[]= array('id'=> $searchResult['id'],
'brandingSettings'=> $searchResult['brandingSettings']);
break;
}
}
When I perform the following:
$popular_posts = $this->Blog->find('all', array('limit' => 5));
I get the following:
Array
(
[0] => Array
(
[Blog] => Array
(
[id] => 4fcfb37d-3eb0-4ec2-a744-175c987a2b72
[title] => This is a post example2
[short_description] => You've stumbled across our blog! Welcome! Here
[created] => 2012-06-06 21:46:05
[modified] => 2012-06-07 16:01:24
)
[Reply] => Array
(
[0] => Array
(
[id] => 4fcfb305-0c58-421b-9149-175c987a2b72
)
[1] => Array
(
[id] => 4fd0ae9e-dca0-4afe-862c-1258987a2b72
)
)
),
[1] ...
[2] ...
)
How can I order the results by the number of Reply ??? (desc)?
Try this
$data = $this->Blog->find('all',array('group' =>array('Reply.id'),
'order' => array('COUNT(Reply.id) DESC'),
'limit'=> 5));