The online racing simulator
#1 - s1m0n
Like the title says, how to read LFSWorld pubstat data using ASP?
Currently I have some code and I am able to read data but there must be some more advanced or optimized way to read data. I'm using ASPTear to retrieve data, save it to .txt file and than parsing out data to database.
Problem? ASPTear sometimes breaks and data is gathered wrong and I have no idea how to cache data properly.
If anyone is interested I can put my code here.
I've never used or even seen ASP Code, so yeah. I might not be of any help to you. But, if you show me yours, I'll show you mine .
#3 - s1m0n
Here is the code
<%
'Create object to put script at sleep to avoid tarpit
Set Shell = CreateObject("Wscript.Shell")

Dim PathToPB

'Open recordset with players
rst.OPEN "SELECT playerID, playerLFSWNick FROM tblPlayers WHERE playerStatus = 1 OR playerStatus = 2 OR playerStatus = 3", Conn, 3, 1
if not rst.EOF then

'Loop through recordset
Do While Not rst.EOF

'Empty txt file containing data
EmptyTxt(PathToPBTxt)

'URL (path) to LFSWorld Pubstat PB data
PathToPB = PubStatPB & rst("playerLFSWNick")

'Create object to "grab" data from LFSWorld
Dim xobjPB
Set xobjPB = CreateObject("SOFTWING.ASPtear")

'"grab" data from LFSWorld
Dim strRetPB
strRetPB = xobjPB.Retrieve(PathToPB, Request_GET, "test=wille", "", "")

'Destroj object
Set xobjPB = nothing

'Check if there is any record
if Trim(strRetPB) = "pb: racer has no pbs" then
Response.Write("No PB's for: " & rst("playerLFSWNick") & "<br>")
elseif Trim(strRetPB) = "can't reload this page that quickly after another" then
Response.Write("Too soon<br>")
else
'Save data to TXT file
Call SaveToTxt(PathToPBtxt, strRetPB)

'Read data from TXT file and put it into array
dim strPB
redim arrPB(-1)
dim e, objFSPB, objTSPB
set objFSPB = Server.CreateObject("Scripting.FileSystemObject")
set objTSPB = objFSPB.OpenTextFile(PathToPBtxt, ForReading)

e = 1
do until objTSPB.AtEndOfStream
redim preserve arrPB(e)
arrPB(e) = objTSPB.ReadLine
e = e + 1
loop

set objFSPB = nothing
Set objTSPB = nothing

'Parse data from array
Dim fPB
Dim arrPBUpper, SplitPB
Dim PBId, PBTrack, PBCar, PBSplit1, PBSplit2, PBSplit3, PBTime, PBLaps
Dim PBPlayerID, PBTrackID, PBCarID

fPB = 1
arrPBUpper = UBound(arrPB)

Do While Not fPB > arrPBUpper
SplitPB = Split(arrPB(fPB), " ")
PBTrack = SplitPB(0)
PBCar = SplitPB(1)
PBTime = SplitPB(2)
PBLaps = SplitPB(3)

PBPlayerID = rst("playerID")

PBTrackID = GetTrackID_LFSWID(PBTrack)

PBCarID = GetCarID_CarShort(PBCar)

'open recordset with players records and insert or modify record
rst2.OPEN "SELECT playerID, carID, trackID, recordLFSOnline, recordLFSHotLap, recordLFSLapper FROM tblRecords WHERE playerID = " & PBPlayerID & " AND carID = " & PBCarID & " AND trackID = " & PBTrackID & "", Conn, 1, 2
if rst2.EOF then
rst2.AddNew
rst2("playerID") = PBPlayerID
rst2("carID") = PBCarID
rst2("trackID") = PBTrackID
rst2("recordLFSOnline") = PBTime
rst2("recordLFSHotLap") = "0"
rst2("recordLFSLapper") = "0"
rst2.Update
else
if rst2("recordLFSOnline") <> PBTime then
rst2("playerID") = PBPlayerID
rst2("carID") = PBCarID
rst2("trackID") = PBTrackID
rst2("recordLFSOnline") = PBTime
rst2.Update
end if
end if
rst2.Close
fPB = fPB + 1
Loop
end if
'Move to next player
rst.MoveNext
'Empty TXT file
EmptyTxt(PathToPBTxt)
Response.Flush()
'Put script to sleep for 6 seconds
Shell.Popup "", 6
Loop
end if
'Destroy shell object
Set shell = nothing
%>

Seems like alot of code to do very little.

Is ASP any faster then PHP?
#5 - s1m0n
Quote from Dygear :Seems like alot of code to do very little.

Is ASP any faster then PHP?

It's about the same. ASP.NET is much faster and has many functions already implemented which I have to write in ASP manually. But when working long time with ASP it is not easy to migrate to .NET.
Why the middle man TXT file? Why not just parse to an array (in memory) then from their post the the database? This way you would not need to touch the Hard drive twice. (Once for the txt file, then again when the database saves the information).

This gives me an idea. . .

I've not had the time to impalement a cache system within LFSWorldSDK at this time. But I might have a few hours over the weekend to do so. What I would like to do is, parse the (lfsworld) results to an array. From their you could save it to a file, via file_put_contents(serialize($array)), or connect to a database and have it saved there. I think the database might be just a small amount faster if you keep on persistent connections. The database would be alot more complicated then the serialized array, but it might still be worth it.



<?php 
array(
    
'uname' => array(
        
'ctime' => 1181883600,
        
'pb' => array(
            
=> array(
                
'track' => '000',
                
'car' => 'BF1',
                
'time' => 98123,
                
'lapcount' => 345,
            )
        )
        
// Same kida setup for hl and so on.
);
?>

#7 - s1m0n
Interesting idea...
I'm aware that txt file in the middle slows down a bit complete script, but the slow part isn't saving and reading txt file, but saving data from array into db. Also, for my stupid needs I need to have all date from LFSWorld in separate txt file. Reason? In the future I would like to develop something I called "Learning curve", application that would present players improvements in driving through time. Some nice statistical and chart data...
Do you have an idea hot to make saving data form array to db faster?
Now I'm not one for traditional ASP methodology and I come from a background of various other langauges, but it seems to me you're selecting a load of data each time and then adding a new record set.

Two things to speed this up;
1. Write an insert statement manually to avoid the new record set api completely - this avoids the huge amount of data ASP deals with
2. Use transactions so that all the writes occur when the transaction is confirmed, not as each insert occurs
#9 - s1m0n
I'm selecting max one row at a time. Check SELECT statement:
rst.OPEN "SELECT playerID, carID, trackID," + _
"recordLFSOnline, recordLFSHotLap, recordLFSLapper " + _
"FROM tblRecords" + _
"WHERE playerID = " & PBPlayerID & _
" AND carID = " & PBCarID & _
" AND trackID = " & PBTrackID & ""

This selects max one row because player cannot have more than one record on one track driving one car. The idea to track player progress is just an idea. It's not even close to realization.
Quote from s1m0n :This selects max one row because player cannot have more than one record on one track driving one car. The idea to track player progress is just an idea. It's not even close to realization.

Sorry I only briefly looked at it the other day and I missed the point of it.

I'd still use a different method to get the same results - a conditional insert would be much more apt in this situation.
Quote from the_angry_angel :I'd still use a different method to get the same results - a conditional insert would be much more apt in this situation.

It is a great idea. I will give it a try and see if executing times are different. I believe your method should be faster and I have no idea why I didn't write my code like that...

FGED GREDG RDFGDR GSFDG