Log in

View Full Version : [TBA]: Example Code Addition


SamC
23-03-2008, 17:50
Here is a recreation of the example code that comes with the new TBA API. Basically it will generate the performance history of your team as well as videos from the year you indicate. Here's the code,

<?
//this file demonstrates the use of four core functions in The Blue Alliance API.
//CONFIGURATION
//Change to your path to tba_api_client_PHP5.php
include 'tba_api_client_PHP5.php';

$teamnumber = 330;
$season = 2007;
$colorA = '0033FF';
$colorB = 'FFFF00';
$colorC = '0033FF';

//get team
$teams = make_array(get_teams($teamnumber));

//show team data
$overall_record = make_array(get_official_record($teamnumber));

//introduction and basic information
echo "<p>Below is some information about our team, {$teams[0]["informalname"]}, from {$teams[0]["city"]}, {$teams[0]["state"]}. Our overall record at official events is {$overall_record[0]["string"]}.</p>";

echo "<table id=\"list_events\">";
echo "<tr><th>Year</th><th>Event</th><th>Record</th><th>Wins</th></tr>";
$future = "";
$team_events = make_array(get_attendance(NULL, $teamnumber));

foreach ($team_events as $attendance)
{
echo "<tr>";
//get event record
$event = make_array(get_events($attendance["eventid"]));

//show the user some data about this event
if ($event[0]["official"] == false) {
$official_text = "*";
}

//get team's record at event
$record = make_array(get_official_record($teamnumber, $event[0]["eventid"]));

//show data to user
if ($record[0]["sum"] != 0) { $percent = round(($record[0]["win"] / $record[0]["sum"]) * 100) . "%"; } else { $percent = "0%"; }
echo "<td><a target=\"_blank\" href=\"http://www.thebluealliance.net/tbatv/eventlist.php?year={$event[0]["year"]}\">{$event[0]["year"]} </a></td>";
echo "<td><a target=\"_blank\" href=\"{$event[0]["tba_link"]}\">{$event[0]["name"]}</a>{$official_text}</td>";
echo "<td>({$record[0]["string"]})</td>";
echo "<td>Won {$percent}</td>";
echo "</tr>";
}

echo "</table>";

?>

Here are also some videos from our <?php print $season ?> season.
<iframe src="http://www.thebluealliance.net/tbatv/iframe_playlist.php?frontcolor=<?php print $colorA ?>&backcolor=<?php print $colorB ?>&lightcolor=<?php print $colorC ?>&year=<?php print $season ?>&team=<?php print $teamnumber ?>" frameborder="0" height="470" width="395" scrolling="no"></iframe>

Content courtesy TheBlueAlliance.net

Heres is an example of it in action, here (http://www.team330.org/?q=content/team-competition-history)

Greg Marra
23-03-2008, 18:09
Heres is an example of it in action, here (http://www.team330.org/?q=content/team-competition-history)

This is an awesome extension of the demo code. I will add it to the examples with the next API revision.

The link doesn't work for me unless I delete the 'www' though, like this: working demo link (http://team330.org/?q=content/team-competition-history)

walkershane123
12-07-2011, 06:32
just check out this one. i found new examples



Matrics Addition

#include<iostream.h>
#include<conio.h>
#include<stdio.h>

struct matrics
{
int a[4][4], m, n;
};

matrics add_mat(matrics m1, matrics m2); //prototype declared

int main()
{
matrics x1, x2, x3;
int i, j;
cout<<"
Enter the size of matrics
";
cout<<"
Enter rows
";
cin>>x1.m;
cout<<"
Enter columns
";
cin>>x1.n;
cout<<"
Enter the elements (Row-wise & Column-wise)
for(i=0; i<x1.m; i++)
{
for(j=0; j<x1.n; j++)
cin>>x1.a[i][j];
}
cout<<"
Enter the size of 2nd matrics
";
cout<<"
Enter rows
";
cin>>x2.m;
cout<<"
Enter columns
";
cin>>x2.n;
cout<<"
Enter the elements (Row-wise & column-wise)
for(i=0; i<x2.m; i++)
{
for(j=0; j<x2.n; j++)
cin>>x2.a[i][j];
}
x3=add_mat(x1,x2);
cout<<"
The added matrics is
";
for(i=0; i<x3.m; i++)
{
for(j=0; j<x3.n; j++)
cout<<x3.a[i][j]<<" ";
}

matrics add_mat(matrics m1, matrics m2)
{
matrics m3; //object of matrics type
int k, l;
if((m1.m==m2.m) && (m1.n==m2.n))
{ m3.m=m1.m+m2.m;
m3.n=m1.n+m2.n;
}

for(k=0; k<m1.m; k++)
{
for(l=0; l<m1.n; l++)
m3.a[k][l]=m1.a[k][l]+m2.a[k][l];
return (m3);
}
}// end of If loop

else
cout<<"
Addition is not possible
";
}


i need your feedback plz

Andrew Schreiber
12-07-2011, 16:16
Reported.

R.C.
12-07-2011, 16:32
Both links don't seem to work for me atm.

-RC

SamC
15-07-2011, 16:11
Both links don't seem to work for me atm.

-RC

Hasn't been updated since originally posting it, but http://team330.net/?q=content/team-competition-history works. I don't think the API has changed much since then, so it should still work with some minor changes.