/me/likes?limit=999 but it doesn't take all of them? - limit

I had a problem with user_likes who return only few likes but it was a FB limit (around 25)
I added "?limit=9999" :
addhobs($facebook->api('/me/likes?limit=999'),$user->usersId);
It's working, take more likes but not all of them....
Any idea ?
Thank you

Related

Calculate hours for training

I have some hesitations about 3 tables which are type_training , training & payment.
In the table type_training, I have a field named price with 4 amounts: for example:
1 hour 00 = 100 euros
1 hour 30 = 150 euros
2 hour 00 = 200 euros
2 hour 30 = 250 euros
In my page Training , I encode 2 recordings for the same student.
The student Dujardin has booked 3 hours for 300 euros.
In my form Payment, is it possible to retrieve the amount of 300 ?
So, in my Model Payment? I must to calculate the difference between the hour start and the hour end?
I don't know how to do ?
Then, after having retrieved the difference of hours in my example we have 3 hours.
How to I sum my 2 recordings in my field Total ? I have tried this?
$typetraining = Typetraining::find($request->fk_typetraining);
$data = $request->all();
$data['total'] = $typetraining->price + $request->????;
Payment::create($data);
In summary:
1) How to retrieve the difference between hour start & hour end,
2) How to calculate the amounts via the duration of my training?
For information, here is my architecture.
I thank you for your help and your explanations.
Edit: Watercamyan 19/09/2019
I adapat this?
createFromFormat('H:i', $request->get('hour_start'))
Per:
<div class="form-group{{ $errors->has('hour_start') ? 'has-error' : '' }}">
<label for="form-group-input-1">Hour start</label>
<input type="text" name="hour_start" id="hour_start" class="form-control" required="required" value="{{ old('hour_start')}}"/>
{!! $errors->first('hour_start', '<span class="help-block">:message</span>') !!}
</div>
Then, in my model Training I have like error message: Undefined variable: typeseances
$start = Carbon::parse($request->get('hour_start'));
$end= Carbon::parse($request->get('hour_end'));
$mins = $end->diffInMinutes($start, true);
$hoursTraining = $mins/60;
$total = $**typeTraining**->price * $hoursTraining;
I have like error message: Undefined variable: typeseances
I think, as JoeGalind said, you should seriously consider re-archetecting this to be simpler. Having to call a TypeTraining object that has nothing but a price, should indeed be moved up to the Training object. However, let me go through a way to solve it with your existing code.
First, as you said, you need to get the number of hours of the requested training. Unfortunately, you need part hours instead of whole hours to change the price. If you needed whole hours, this would be easy, you could use the Carbon method diffInHours(). But we can do it with diffInMinutes(), and then calculate out the partial hour.
First, we need to parse the hours coming in from the form into a Carbon object:
$start = Carbon::parse($request->get('hour_start'));
$end= Carbon::parse($request->get('hour_end'));
Note, I don't know how it is coming in from your form. You might need to parse it differently if the above doesn't work. Something like:
createFromFormat('H:i', $request->get('hour_start'))
or
createFromFormat('H:i:s', $request->get('hour_start'))
Now that you've got a carbon object, we need to calculate out the difference, including the part hours. Again, we'll use the minutes and calculate for part hours:
$mins = $end->diffInMinutes($start, true);
$hoursTraining = $mins/60;
This will yield your multiplier (the number of hours training), something like 2.0 or 2.5 or 2.25, etc. From here, if you have a base price for one hour (which is what I expect is in that TypeTraining model's price field), it is easy:
$total = $typeTraining->price * $hoursTraining;
The hard part, based on the way you have your code set up, is that you must pull the TypeTraining along with the Training, in order to know the price (again - just stick the price on the training to make life easier).
To get the price, something like this:
$training = Training::with('typeTraining')->where('fk_student', $request->get('fk_student)->first();
$price = $training->typeTraining->price;
Now you have the price to plug into the formula above.
This is surely not exact. And pulling the training with the FK on student is probably not what you want. If it is generic training, or there is some other identifier, use that to pull the training to get the price. But you can decide that later. I can only guess at some of this, as I don't know what's coming in, or what your query needs to be, or your relationships, but this should give you an idea. Most importantly, you were asking for how to calculate total, which is answered farther above.
I would recommend the following:
Add a "price" field to the training table. This way, if in the future, you increment that price, all your history stays with the current price.
After saving your "training", go ahead and calculate the hours between both dates using Carbon library, and select your current price from the TypeTraining table using this value.
Store the value on the Training table and then you can easily calculate the sum from anywhere.

Query with sum many columns from same table with laravel query

This seems very easy query but can't translate it into laravel query. I have table orders there are two columns total_usd and total_gbp. I want to sum each column to get total of usd and total of gbp on the page.
This query is working in phpmyadmin and I got correct result
SELECT sum(order_total_usd) as usd, sum(order_total_gbp) as gbp FROM `orders`
In laravel I've tried this
$sumOrders = Order::select('sum(order_total_gbp) as gbp, sum(order_total_usd) as usd');
when I dd($sumOrders) I've one really huge output which almost cause browser to freeze.
Where is my mistake here?
You can try something like this
$sumOrders = Order::select( \DB::raw("sum(order_total_gbp) as gbp"), \DB::raw("sum(order_total_usd) as usd"))->get();
You can use selectRaw
$sumOrders = Order::selectRaw('sum(order_total_gbp) as gbp, sum(order_total_usd) as usd');
Except for one missed word, your code is OK. Add "Raw" after "select" as shown:
$sumOrders =
Order::selectRaw(
'sum(order_total_gbp) as gbp,
sum(order_total_usd) as usd'
);
Just replace "Order::select(...)" with Order::selectRaw(...).
Have a great day!

very basic pig-latin beginner code

I am new to hadoop and all its derivatives. And I am really getting intimidated by the abundance of information available.
But one thing I have realized is that to start implementing/using hadoop or distributed codes, one has to basically change the way they think about a problem.
I was wondering if someone can help me in the following.
So, basically (like anyone else) I have a raw data.. I want to parse it and extract some information and then run some algorithm and save the results.
Lets say I have a text file "foo.txt" where data is like:
id,$value,garbage_field,time_string\n
1, 200, grrrr,2012:12:2:13:00:00
2, 12.22,jlfa,2012:12:4:15:00:00
1, 2, ajf, 2012:12:22:13:56:00
As you can see that the id can be repeated.This id can be like how much money a customer has spent!!
What I want to do is save the result in a file which contains how much money each of the customer has spent in "morning","afternoon""evening""night"
(You can define your some time buckets to define what morning and all is.
For example here probably
1, 0,202,0,0
1 is the id, 0--> 0$ spent in morning, 202 in afternon, 0 in evening and night
Now I have a python code for it.. But I have to implement this in pig.. to get started.
If anyone can just write/guide me thru this.. Thats all I need to get started.
Thanks
I'd start like this:
foo = LOAD 'foo.txt' USING PigStorage(',') AS (
CUSTOMER_ID:int,
DOLLARS_SPENT:float,
GARBAGE_FIELD,
TIME_STRING:chararray
);
foo_with_timeslots = FOREACH foo {
GENERATE
CUSTOMER_ID,
DOLLARS_SPENT,
/* DO TIME SLOT CALCULATION HERE */ AS TIME_SLOT
;
}
I don't have much knowledge of date/time values in pig, so I'll leave how to do conversion from time string to timeslot, to you.
id_grouped_foo_with_timeslots = GROUP foo_with_timeslots BY (
CUSTOMER_ID,
TIME_SLOT
);
-- Calculate how much each customer spent at time slots
spent_per_customer_per_timeslot = FOREACH id_grouped_foo_with_timeslots {
GENERATE
group.CUSTOMER_ID as CUSTOMER_ID,
group.TIME_SLOT as TIME_SLOT,
SUM(foo_with_timeslots.DOLLARS_SPENT) as TOTAL_SPENT
;
}
You'll have an output like below in spent_per_customer_per_timeslot
1,Morning,200
1,Evening,100
2,Afternoon,30
At this point it should be trivial to re-group the data and put it in the shape you want.

Wrong amount for item in Quote and Order

Hi i have a question regarding tax_amount, row_total, price_incl_tax and row_total_incl_tax.
My problem is that those values are caclulated as follow:
price = 30
price_excl_tax = 25.08
so for ex: price_incl_tax should be 30, but it is 25.08...
base_tax amount is good, it's calculated from price (30), but tax_amount is calculated from price_excl_tax
Did someone encoutered this issue ?
Ok, so it looks like it isn't problem with Magento itsefl, but with Thread Interference on PHP side.

How can this query be improved?

I am using LINQ to write a query - one query shows all active customers , and another shows all active as well as inactive customers.
if(showall)
{
var prod = Dataclass.Customers.Where(multiple factors ) (all inactive + active)
}
else
{
var prod = Dataclass.Customers.Where(multiple factors & active=true) (only active)
}
Can I do this using only one query? The issue is that, multiple factors are repeated in both the queries
thanks
var customers = Dataclass.Customers.Where(multiple factors);
var activeCust = customers.Where(x => x.active);
I really don't understand the question either. I wouldn't want to make this a one-liner because it would make the code unreadable
I'm assuming you are trying to minimze the number of roundtrips?
If "multiple factors" is the same, you can just filter for active users after your first query:
var onlyActive = prod.Where(p => p.active == true);
Wouldn't you just use your first query to return all customers?? If not you'd be returning the active users twice.
Options I'd consider
Bring all customers once, order by 'status' column so you can easily split them into two sets
Focus on minimizing DB roundtrips. Whatever you do in the front end costs an order of magnitude less than going to the DB.
Revise user requirements. For ex. consider paging on results - it's unlikely that end user will need all customers at once.

Resources