ClickListener only works for elements in Table Libgdx - libgdx

I have a table extended main class (table_A). Inside table_A class i have a method which function is to add new table (table_b) into my table_A (for achieving scrollpane result), at the same time assign click listener to the table_b.
I though by adding clicklistener (ck) to table_b will makes table_b detectable. However, only the elements in the table_b able to make detection from clicklistener.
Please help
My table_A adding table function as follow:
public void addRow(Table newRow){
scrollTable.row();
scrollTable.add(newRow).width(newRow.getWidth()).pad(10);
newRow.addListener(ck);
newRow.debug();
newRow.setName(stage++ +"");
}
My debug table goes as:
My table_b codes goes as:
add(challengeLabel).colspan(10).expandX().align(Align.left).fill();
row();
add(star1).colspan(1).size(starSpaceWidth, star1.getHeight() / star1.getWidth() * starSpaceWidth).expandX().fillX().align(Align.right);
add(star2).colspan(1).size(starSpaceWidth, star1.getHeight() / star1.getWidth() * starSpaceWidth);
add(star3).colspan(1).size(starSpaceWidth, star1.getHeight() / star1.getWidth() * starSpaceWidth);
add(star4).colspan(1).size(starSpaceWidth, star1.getHeight() / star1.getWidth() * starSpaceWidth);
add(star5).colspan(1).size(starSpaceWidth, star1.getHeight() / star1.getWidth() * starSpaceWidth);

If you take a look in Table's constructor, you see this line:
setTouchable(Touchable.childrenOnly);
It is causing your troubles. Change it for your table_B.

Related

KDB type error - whilst using functional select/updates

I have the below two functions - the idea here is that id like to create percentiles of bpsAum for different programmes, i also have another function for bpsTrn, id like the limits table to be one single function that both can share. This however, returns a type error, I think it has to do with me using functional selects and updates within the functions. would appreciate any advice here. Outside of the function, running line by line this works fine, just not when packaged into function.
.tca.dailySlippageDistribution4:{[Dte;lookback;thresh]
tab:select bpsAum:(sum ArrivalSlippageUSD % first TradingLevel),sum TurnoverUSD by ProgrammeName,date from fullSlipTable where date within(Dte - 1500;Dte);
prog: exec distinct ProgrammeName from tab;
dtes: exec distinct date from tab;
Dte2:Dte - lookback;
Dte2:?[Dte2 in dtes;Dte2;?[(Dte2-1) in dtes;Dte2:Dte2-1;?[(Dte2-2) in dtes;Dte2:(Dte2-2);Dte2]]];
Dte:?[Dte in dtes;Dte;?[(Dte-1) in dtes;Dte:Dte-1;?[(Dte-2) in dtes;Dte:(Dte-2);Dte]]];
st:dtes?Dte;
ed:dtes?Dte2;
distwindow:(st-ed)-1;
metric:`bpsAum;
maW:0;
Limits:(uj/){[tab;thresh;distwindow;metric;maW;x] LimitsTable4[tab;thresh;distwindow;metric;maW;x]}[tab;thresh;distwindow;metric;maW;] each prog;
tab:ej[`date`ProgrammeName;tab;Limits];
tab};
LimitsTable4:{[tab;thresh;distwindow;metric;maW;prog]
tab: select from tab where ProgrammeName = prog;
tab:$[metric ~ `bpsTrn;![tab;();0b;(enlist `maRunRate)!(enlist (mavg;maW;metric))];tab];
dateList: exec date from tab;
LList:$[`maRunRate in cols tab;?[tab;();();`maRunRate];?[tab;();();`metric]];
ltk:`float$swin[.dashFn.getPercentile[thresh(1);];distwindow;LList];
utk:`float$swin[.dashFn.getPercentile[thresh(0);];distwindow;LList];
tab:?[metric ~ `bpsAum;([]date:dateList;ProgrammeName:prog;bpsAum:LList;upperLimit:utk;lowerLimit:ltk);([]date:dateList;ProgrammeName:prog;maBpsTrn:LList;upperLimit:utk;lowerLimit:ltk)];
tab:(-1*distwindow)# tab};

GEO location inversed PHP and SQL

I'm currently working on a campaign/advertisement script in Laravel 5.2. I'm having a table with ads, for example: Ad name, Location (lat/long), Radius (+10km).
Now I have a user location (lat/long). I want to see if he is in the radius of any ad and show the ad to him.
When I search on Google I only find solution to search ads based on lat/long + radius but I want to opposite. So see if a lat/long is in a radius of existing ads.
What is the best way to make this? And advice would be appreciated
This should work, all you would need to do is add this function to your User model.
public function ads()
{
return \App\Ad::
crossJoin('users', 'users.id', '=', \DB::raw($this->attributes['id']))
->where(\DB::raw('69 * DEGREES(ACOS(COS(RADIANS(users.Latitude)) * COS(RADIANS(ads.Latitude)) * COS(RADIANS(users.Longitude - ads.Longitude)) + SIN(RADIANS(users.Latitude)) * SIN(RADIANS(ads.Latitude))))'), '<=', 'ads.radius')
->get();
}
It's not a traditional Eloquent relationship so you won't be able to eager load it, although I'm sure that would be possible with more work.
In order to find a user's ads, you would simply do something like the following...
$ads = (new \App\User::find($user_id))->ads();
Note that this assumes both your users table and ads table contains a longitude and latitude column. It also assumes your ads table has a radius column. You might need to rename some columns but it should give you what you need.
Also this assumes your radius is in miles. If you use km, instead of 69, use 111.1111.
I have made some changes to the version of you user3158900.
Made a scope out of the function and the lat/long from the user is variable so I need them as a input in the query.
I now have this:
public function scopeAdsInLocation($query, $from_latitude, $from_longitude)
{
$query = CampaignModel::
where(\DB::raw('111.1111 * DEGREES(ACOS(COS(RADIANS(' . $from_latitude . ')) * COS(RADIANS(campaigns.loc_lat)) * COS(RADIANS(' . $from_longitude .' -
campaigns.loc_long)) + SIN(RADIANS(' . $from_latitude . ')) * SIN(RADIANS(campaigns.loc_lat))))'), '<=', 'campaigns.loc_radius')
->get();
return $query;
}
I call it like this:
$ads = CampaignModel::adsInLocation(51.191320, 5.987772);
var_dump($ads);
This code works, but only if I set the radius to a fixed value. So when I replace campaigns.loc_radius with '100' it works. But with the radius each campaign has it doesn't seem to do the job. Do you know maybe why? Or have a solution for this.

MySQL Restraint Not Being Passed Down Through Views

I am working with a system that has multiple views chained upon each other. For some reason, there is a problematic view which isn't passing the restraint down through the chain (despite them having a key in common). For example, here is the visual explain statement. Visual Explain of SQL View
As you can see, the main view is based upon two other views (which, in turn, are based off another set of views). The problem view in this example is ResourcePointsAndCategories (on the right-hand side bottom). In this query, I am restraining results by a WHERE clause based on a column called HostID. HostID is in my supporting view; however, the key is not being passed down, and therefore, the view is loading 23,000 rows, instead of the 3 I want.
Any help to explain or correct this issue would be greatly appreciated. Thanks!
Edit: Sorry, should have included the code from the start:
Here is for the main view:
VIEW `test`.`resourcepointswithlookupsandcategorycountandportalpagescount` AS
SELECT
`resourcepointswithlookups`.`URL` AS `URL`,
`resourcepointswithlookups`.`Format` AS `Format`,
`resourcepointswithlookups`.`Host` AS `Host`,
`resourcepointswithlookups`.`ResourceID` AS `ResourceID`,
`resourcepointswithlookups`.`HostID` AS `HostID`,
`resourcepointswithlookups`.`PermitID` AS `PermitID`,
`resourcepointswithlookups`.`ResourceTitle` AS `ResourceTitle`,
`resourcepointswithlookups`.`FormatID` AS `FormatID`,
`resourcepointswithlookups`.`TypeID` AS `TypeID`,
`resourcepointswithlookups`.`Notes` AS `Notes`,
`resourcepointswithlookups`.`Description` AS `Description`,
`resourcepointswithlookups`.`ReferenceFirstName` AS `ReferenceFirstName`,
`resourcepointswithlookups`.`ReferenceLastName` AS `ReferenceLastName`,
`resourcepointswithlookups`.`ReferenceEmail` AS `ReferenceEmail`,
`resourcepointswithlookups`.`ReferencePermission` AS `ReferencePermission`,
`resourcepointswithlookups`.`ReferenceComment` AS `ReferenceComment`,
`resourcepointswithlookups`.`CreateDate` AS `CreateDate`,
`resourcepointswithlookups`.`CreateBy` AS `CreateBy`,
`resourcepointswithlookups`.`LastEditDate` AS `LastEditDate`,
`resourcepointswithlookups`.`LastEditBy` AS `LastEditBy`,
`resourcepointswithlookups`.`LastReview` AS `LastReview`,
`resourcepointswithlookups`.`LastReviewBy` AS `LastReviewBy`,
`resourcepointswithlookups`.`Type` AS `Type`,
`resourcepointswithlookups`.`LibraryURL` AS `LibraryURL`,
`resourcepointswithlookups`.`TypeCollection` AS `TypeCollection`,
`resourcepointsandcategoriescount`.`CategoryCount` AS `CategoryCount`,
`portalpagecountwithresourcepointsandportaltitle`.`PortalPageCount` AS `PortalPageCount`,
`resourcepointswithlookups`.`NormFileStatus` AS `NormFileStatus`,
`resourcepointswithlookups`.`NormFileStatusDate` AS `NormFileStatusDate`,
`resourcepointswithlookups`.`FileSystemStatus` AS `FileSystemStatus`,
`resourcepointswithlookups`.`FileSystemStatusDate` AS `FileSystemStatusDate`,
`resourcepointswithlookups`.`LanguageName` AS `LanguageName`,
`resourcepointswithlookups`.`LanguageCode` AS `LanguageCode`
FROM
((`test`.`resourcepointswithlookups`
LEFT JOIN `test`.`portalpagecountwithresourcepointsandportaltitle` ON ((`resourcepointswithlookups`.`ResourceID` = `portalpagecountwithresourcepointsandportaltitle`.`ResourcePointID`)))
LEFT JOIN `test`.`resourcepointsandcategoriescount` ON ((`resourcepointswithlookups`.`ResourceID` = `resourcepointsandcategoriescount`.`ResourceID`)))
And here's the code for the problem view:
VIEW `test`.`resourcepointsandcategoriescount` AS
SELECT
`resourcepointsandcategories`.`ResourceID` AS `ResourceID`,
`resourcepointsandcategories`.`HostID` AS `HostID`,
COUNT(`resourcepointsandcategories`.`CategoryID`) AS `CategoryCount`
FROM
`test`.`resourcepointsandcategories`
GROUP BY `resourcepointsandcategories`.`ResourceID`
And, ultimately, the view the problem view is based off of (which runs fine):
VIEW `test`.`resourcepointsandcategories` AS
SELECT
`test`.`resourcepoints`.`ResourceID` AS `ResourceID`,
`test`.`resourcepoints`.`HostID` AS `HostID`,
`test`.`lkupegcategories`.`Category` AS `Category`,
`test`.`resourcepointcategories`.`CategoryID` AS `CategoryID`
FROM
((`test`.`resourcepointcategories`
JOIN `test`.`resourcepoints` ON ((`test`.`resourcepointcategories`.`ResourceID` = `test`.`resourcepoints`.`ResourceID`)))
LEFT JOIN `test`.`lkupegcategories` ON ((`test`.`lkupegcategories`.`eGCategoryID` = `test`.`resourcepointcategories`.`CategoryID`)))
The query I am calling is:
SELECT * FROM test.resourcepointswithlookupsandcategorycountandportalpagescount WHERE HostID = 4532;
If I read your views correctly, you are filtering the first (big) view on HostID = 4532, but not filtering the other two views on it.
Perhaps the ON clauses need to include AND res....HostID = res...HostID.

Cocos2d-x :Fade in list of items by sequence with different location

I'm newbie in Coco2d-x
I have a list of items (could be text)
I want to display them by sequence, one by one per 1 second in different location.
For example i have an array like items[50]
Thanks for all your help.
I have pasted few code below to show you how ccsequence works
CCFadeIn * fadeInText = CCFadeIn::create;
CCDelayTime * Delay = CCDelayTime::create(0.5f);
CCFadeIn * fadeInText2 = CCFadeIn::create;
CCCallFunc * funGame = CCCallFunc::create(this,callfunc_selector(HelloWorld::funcGame));
CCSequence *Sequence = CCSequence::create(fadeInText, readyDelay, fadeInText2, funGame, NULL);
myObject->runAction(Sequence);

MySQL - Perl: How to get array of zip codes within submitted "x" miles of submitted "zipcode" in Perl example

I have found many calculations here and some php examples and most are just over my head.
I found this example:
SELECT b.zip_code, b.state,
(3956 * (2 * ASIN(SQRT(
POWER(SIN(((a.lat-b.lat)*0.017453293)/2),2) +
COS(a.lat*0.017453293) *
COS(b.lat*0.017453293) *
POWER(SIN(((a.lng-b.lng)*0.017453293)/2),2))))) AS distance
FROM zips a, zips b
WHERE
a.zip_code = '90210' ## I would use the users submitted value
GROUP BY distance
having distance <= 5; ## I would use the users submitted value
But, I am having trouble understanding how to implement the query with my database.
It looks like that query has all I need.
However, I cannot even find/understand what b.zip_code actually is! (whats the b. and zips a, zips b?)
I also do not need the state in the query.
My mySQL db structure is like this:
ZIP | LAT | LONG
33416 | 26.6654 | -80.0929
I wrote this in attempt to return some kind of results (not based on above query) but, it only kicks out one zip code.
## Just for a test BUT, in reality I desire to SELECT a zip code WHERE ZIP = the users submitted zip code
## not by a submitted lat lon. I left off the $connect var, assume it's there.
my $set1 = (26.6654 - 0.20);
my $set2 = (26.6654 + 0.20);
my $set3 = (-80.0929 - 0.143);
my $set4 = (-80.0929 + 0.143);
my $test123 = $connect->prepare(qq{SELECT `ZIP` FROM `POSTAL`
WHERE `LAT` >= ? AND `LAT` <= ?
AND `LONG` >= ? AND `LONG` <= ?}) or die "$DBI::errstr";
$test123->execute("$set1","$set2","$set3","$set4") or die "$DBI::errstr";
my $cntr;
while(#zip = $test123->fetchrow_array()) {
print qq~$zip[$cntr]~;
push(#zips,$zip[$cntr]);
$cntr++;
}
As you can see, I am quite the novice so, I need some hand holding here with verbose explanation.
So, in Perl, how can I push zip codes into an array from a USER SUBMITTED ZIP CODE and user submitted DISTANCE in miles. Can be a square instead of a circle, not really that critical of a feature. Faster is better.
I'll tackle the small but crucial part of the question:
However, I cannot even find/understand what b.zip_code actually is! (whats the "b." and "zips a, zips b"?)
Basically, the query joins two tables. BUT, both tables being joined are in fact the same table - "zips" (in other words, it joins "zips" table to itself"). Of course, since the rest of the query needs to understand when you are referring to the first copy of the "zips" table and when to the second copy of the "zips" table, you are giving a table alias to each copy - to wit, "a" and "b"'.
So, "b.xxx" means "column xxx from table zips, from the SECOND instance of that table being joined".
I don't see what's wrong with your first query. You have latitude and longitude in your database (if I'm understanding, you're comparing a single entry to all others). You don't need to submit or return the state that's just part of the example. Make the first query work like this:
my $query = "SELECT b.zip_code,
(3956 * (2 * ASIN(SQRT(
POWER(SIN(((a.lat-b.lat)*0.017453293)/2),2) +
COS(a.lat*0.017453293) *
COS(b.lat*0.017453293) *
POWER(SIN(((a.lng-b.lng)*0.017453293)/2),2))))) AS distance
FROM zips a, zips b WHERE
a.zip_code = ?
GROUP BY distance having distance <= ?";
my $sth = $dbh->prepare($query);
$sth->execute( $user_submitted_zip, $user_submitted_distance );
while( my ($zip, $distance) = $sth->fetchrow() ) ) {
# do something
}
This won't be that fast, but if you have a small record set ( less than 30k rows ) it should be fine. If you really want to go faster you should look into a search engine such as Sphinx which will do this for you.
fetchrow_array returns a list of list references, essentially a two-dimensional array, where each row represents a different result from the database query and each column represents a field from the query (in your case, there is only one field, or column, per row).
Calling while ($test123->fetchrow_array()) will cause an infinite loop as your program executes the query over and over again. If the query returns results, then the while condition will be satisfied and the loop will repeat. The usual idiom would be to say something more like for my $row ($test123->fetchrow_array()) { ..., which will only execute the query once and then iterate over the results.
Each result is a list reference, and the zip code you are interested in is in the first (and only) column, so you could accumulate the results in an array like this:
my #zips = (); # for final results
for my $row ($test123->fetchrow_array()) {
push #zips, $row->[0];
}
or even more concisely with Perl's map statement:
my #zips = map { $_->[0] } $test123->fetchrow_array()
which does the same thing.