How can I query certain trading days using YQL? - php

I'm using PHP to build queries in YQL and the Yahoo! Finance API and retrieve historical stock prices. I'm looking for trends over the last 5 trading days (NOT calendar days). The syntax looks like this:
select * from yahoo.finance.historicaldata where symbol = "YHOO" and startDate = "yyyy-mm-dd" and endDate = "yyyy-mm-dd"
This works fine, but the dates are calendar dates, ie if the start date is the Friday before a three-day weekend, I don't get much useful data. Is there:
Some form of expression I can use in the query to specify this (Google Sheets, for instance, lets you subtract a number of days from a given date, and assumes those dates are trading days), or
Some external API or calendar I can use to retrieve and insert the correct start date explicitly?
If this is a case of RTM, forgive me, but please link me to TFM, because I can't seem to find it.

Related

What is the best practice in creating scheduling calendar in php and html?

I want to create a website with an scheduling calendar.
My first idea is to use some free calendar template or download some free scheduling calendar. Then in my scheduling form, when someone request for an schedule, I will get the date he/she input and save it into the database then show it to the scheduling calendar.
But someone told me that, in my database, I should create a calendar table.
Which is the best way around?
The first one with only one table for schedule on my database or the second one with two tables for schedule and calendar?
I hope you get my idea.
It could be first one. One of option is to keep data by day of year.
you can draw your own calendar by counting day of year
actual day of yaer - date('z') + 1; //+ 1 because it is an array it starts from 0
then you can get number of days in each month
cal_days_in_month
and loop it x 12 with
here will be day of month with css style so it looks like calendar field
your i++ will bee number of days in month of course.
Keep records in database by year and day of year. you can do so much things this way

PHP MySQL Table w AJAX: Filling in data for the whole year (day by day, only showing 7 days at once)

I’m struggling on how to design this small application. It’s going to be a table info where the columns will be dates and only 7 dates will be shown at any given time (the current day, plus the next six days).
The user NEEDS to be able to scroll to the left (or right, I suppose) and see previous dates with information that has bee entered for specific dates (ie, user wants to see the # of Service Jobs for February 14th, 2015).
What I have so far:
In this case there are 6 rows of information. The user can go in and edit this information. All of this data needs to be posted to a database, and the dates need to account for the whole year (ie, 1/1 to 12/31) and this has to happen every year. I’ve worked with the x-editable plugin a bit and have had some success, but I’m having a difficult time understanding how to account for all the differernt days of the year (365) and how to incorporate that into a MySQL database.
Current'y the 6 dates you see at the top of the img are shown using Javascript. The little dotted lines below the row values are from the X-editable plugin, and when you update this info it is posted to a database with a timestamp.
So my question is: how in the world do I account for 365 days for the year? It's not like I want 365 columns, each representing one day of the year, that seems crazy. (and the same thing will have to happen for 2016, 2017, etc etc...ongoing data).
I'm not sure if I've been taking the right approach on this. Feel like I'm making it much more painful than it needs to be.
Any input on how to design such an application would be greatly appreciated.
From a high level; I would just use an indexed DATE column.
A quick example:
<?php
$date_start = date('Y-m-d'); // Today
$date_end = date('Y-m-d', strtotime($date_start . ' + 6 days'));
// Assuming you have a PDO DB handler setup at this point...
$stmt = $dbh->prepare('SELECT * FROM `table` WHERE `day` BETWEEN ? AND ? ORDER BY `day` ASC');
$stmt->execute(array($date_start, $date_end));
$res = $stmt->fetchAll();
var_dump($res);

Google Analytics Apiget total amount

I am trying to work with the Google analytics API. I use following code to request data:
$ga = new gapi($ga_email,$ga_password);
$ga->requestReportData($ga_profile_id,'date',array('pageviews', 'visits'), 'date', "",$start,$end,1,1000);
$results = $ga->getResults();
Which can then be iteratd with a loop for each date
After googling I can't seem to find the answer or it is possible to get the total visits, pageviews, newvisits, uniquevisits,percentnewvisits.... for a certain timespan?
If you request for example.
Dimesnion: Date
Metrics: Pageviews,visits, UniqueVists
StartDate: 20130101
endDate: 20130201
You will have a row for each date between Startdate and endDate with the values summed up for that
date.
If what you want is them summed up for all the dates then You could try a dimension like Visitor type then you will only end up with 2 rows new visits and returning visits. Summed up for the time between startdate and end date.
Unfortuantly you have to select at least one dimension so you cant just get the Metrics. Using Visitor type should work then you only have to sum up the two rows that come back. Another idea would be if your start date and end date have the same Year then you could use ga:year as your dimension. Then you will only have one row summed up with all your metrics.
Edit: found something else.
You could also try looking at totalsForAllResults it appears to be returned in the V3 of the core reporting client library.

PHP MYSQL event sheduler like Musicteacherhelper.com

I have search over php mysql recurring events but didnt find anything exactly like i want.
I want to develop event sheduler in php mysql in which user add reccuring events based on daily,weekly,montly,yearly patterns using html form which is stored in mysql using php.
Like for example
user will enter start date,end date, what time event will happen(like 4:30pm) and duration of the event(like 2 hrs so it will make 430pm to 630pm event) with repeating patterns.For example event will repeat after 3 days , on monday and wednesday every week or after every two weeks, every 10th day of month or every 10th day after two months, on specific date every year or without any repeating patterns just add event for any specific date .
This information will be taken from user using html form and will be stored in mysql database and than it needs to display user upcoming events(e.g consider today is 13th july 2013 if recurring event is sheduled for 15th july 2013 it will consider as upcoming events) or events in the past(e.g consider today is 13th july 2013 if event is sheduled for 10th july 2013 it will be consider as past event) using php in two different ways using html table and arshaw full calendar.
I need help how i store event information in mysql database and than pull it using php and display upcoming or past events in html table and also be to integrate it arshaw full calendar.
This sort of stuff is already working in musicteacherhelper.com which also used php and mysql for implementing so i need to know is there any open source code available to implement this functionality.
Any help in this regard will be highly appreciated.
Thanks
Talha
use industry standard RRULE to store the informaton and some metadata of event in some mysql table for search purpose (example : date range)
http://www.kanzaki.com/docs/ical/rrule.html
demo : http://jkbr.github.io/rrule/
there are js and php libraries available for the same.

Average of dates per months to Graph, how?

I working on a website codeigniter based. In my database i have a lot of dates in this format:
yyyy-mm-dd hh:mm:ss
What i want is to represent in a graph, all the 12 months, and for each month the total of dates that i have on my database. For now just a graph for 2012, next year ill change it for 2013.
How can i do it? Any ideas?
I searched a lot for javascript graph/tables such as in google api but none of them gave me everything i needed. Also, how can i read from database the dates and "put them" in each month.
Thanks
At first extract your average dates from Database with for example this code:
SELECT ROUND(AVG(UNIX_TIMESTAMP(`date`)),0) as avg_time
FROM `data`
WHERE `id`>0
GROUP BY Month(`date`)
This SQL works fine and returns average unix_timestamp rounded to the nearest and grouped in Months. In PHP code u can easily cover back to datetime format if needed.
Also u can add in WHERE closure check for year. For example: WHERE YEAR(date)=2012.
Good luck :)

Categories