Forum Moderators: open

Message Too Old, No Replies

ASP Rotation script, based on weight

can anyone provide?

         

mattglet

1:41 am on Nov 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i am looking for an ASP rotation script that works much like an ad-rotator. here's the catch: it's not for an ad-rotator, so i can't use any of pre-built ad-rotator stuff. the main piece of the pie i'm looking for is the algorithm that shows how the action weight is calculated.

i.e.
action 1 happens 70% of the time
action 2 happens 20% of the time
action 3 happens 10% of the time

how do you calculate when a certain action should happen, if it's getting out of percentage?

-Matt

plumsauce

2:07 am on Nov 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




do a string vector

1111111223

then index into the vector using the modulus
of the invocation of the page, keeping the
counter in an application variable.

mattglet

3:52 am on Nov 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



plumsauce-

i fully appreciate your help, but i must ask you to dumb that down a little bit :)

also, i need something that will handle extreme scalability. will this still work? over time, this function could be run about 10k times per day.

-Matt

plumsauce

4:53 am on Nov 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




i mean,

start a counter at 0

increment counter each use

save counter to application variable

use (counter modulo 10) as an index into the vector

1111111223

to determine which action to take,

notice there are

7 x action 1
2 x action 2
1 x action 3

which are your desired proportions

this is EXTREMELY scalable

willybfriendly

5:41 am on Nov 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cool idea plumsauce! I would have used a random number with an if/else construct:

if random < 7
else if random > 8
else

WBF

mattglet

1:53 pm on Nov 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



plumsauce-

how does that keep track if a something is getting out of ratio? isn't the counter only keeping track of total instances, rather than individual instances?

-Matt

aspdaddy

5:56 pm on Nov 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



a map container, vbScribt dictionary or 2d array would be ideal for this.

Store the action name in the key and increment its value each time that action occurs.

The sum of all the values gives the total number of actions, you can use this to work out the %age each action has occured.

mattglet

6:03 pm on Nov 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



aspdaddy-

would it be possible for you to write up some pseudo-code of what you are describing?

-Matt

aspdaddy

6:31 pm on Nov 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



a little rough but something like:

// application level
// set %ages
action1=10;action2=20;action3=70;

// create a 2-column structure
actions()=new map;

// page level

// get current action
x=thisAction();

// record action name and increment counter
actions(x).value() ++;

// work out the total number of actions
for i=actions.start()...actions.end()
{
total= total + actions[i].value()
}

// tests will be something like this
// standard %age calculations
if ( actions("action1").value() / total * 100 < action1 )
{
// action1 is below 10%
}

TheNige

8:29 pm on Nov 13, 2003 (gmt 0)

10+ Year Member



ASP has a built in content rotator that reads a text file with weighted values.

mattglet

8:31 pm on Nov 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



it's an ad-rotator, which is not applicable for this instance.

-Matt

Zaphod Beeblebrox

9:26 am on Nov 14, 2003 (gmt 0)

10+ Year Member



Why not simply use the built-in Ad Rotator object, and build a Select Case around the result of that?

[w3schools.com...]


Select Case adrot.GetAdvertisement("ads.txt")
Case ...
End Select

mattglet

12:52 pm on Nov 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



here's the catch: it's not for an ad-rotator, so i can't use any of pre-built ad-rotator stuff.

TheNige

8:24 pm on Nov 14, 2003 (gmt 0)

10+ Year Member



please check the ASP 3.0 documentation..there is a content rotator.

Set cr=Server.CreateObject( "MSWC.ContentRotator" )

if you can't use this...what exactly are you trying to do? All the talk I have seen is just about the algo you are trying to make...what kind of content do you need to rotate?

mattglet

12:01 am on Nov 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



very helpful TheNige.

that may be what i'm looking for.

i'm building a page that when a user visits it, the page will redirect to other specfied pages, based on the weight. i just need to figure out how i'm going to get the redirects to work. that's why i was looking for an asp-based algorithm, so i didn't have to worry about text files.

-Matt

TheNige

2:52 am on Nov 15, 2003 (gmt 0)

10+ Year Member



you may still need the text file with the content rotator as that is where you put the weights...but it would simply return the urls or whatever else you decided...in which you would then just pass those to your redirect statement..in theory.

TheNige

2:55 am on Nov 15, 2003 (gmt 0)

10+ Year Member



also..your text file really doesn't have to be a plain old text file....you might be able to make it an ASP page that dynamically pulls your links and weights from a database or XML file....the ASP page would then just render the text when it is called from the content rotator control.

mattglet

3:03 pm on Nov 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



TheNige-

making the text file an asp file is allowable, but it doesn't render the ASP into text.

here's my setup:

rotator.asp-

<%
dim cr
Set cr=Server.CreateObject( "MSWC.ContentRotator" )
%>

<P><%=cr.ChooseContent("rotatortxt.asp")%></P>

rotatortxt.asp-

%% #1
<%="works"%>

%% #2
<%="works"%>

%% #3
<%="works"%>

%% #4
<%="works"%>

here is the output when i call rotator.asp (asp tags are not being rendered):

<P><%="works"%>
</P>

any ideas?

-Matt

mattglet

3:08 pm on Nov 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i must say that ultimately, i'm going to be pulling the weights and redirect values from a database.

-Matt

TheNige

8:00 pm on Nov 18, 2003 (gmt 0)

10+ Year Member



ahhh...I guess that it reads it as straight text and doesn't run it as asp. The only other way to get the text file semi-dynamic would be to export it from SQL Server using DTS on a schedule, or a script that writes out the values to a text file.

mattglet

8:17 pm on Nov 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



yeah, i'm working on using FSO to create the txt file for the content rotator. it just would have been nice to use a database. oh well.

thanks for all your help.

-Matt

RossWal

9:20 pm on Nov 18, 2003 (gmt 0)

10+ Year Member



I did this once for a random photo display. IIRC it went something like this:

Get frequency and url rows from database

for i = 0 to rs.count
for j = 0 to thisrow.frequency
randomize a key
add the key and the url into a dictionary object
next
next

Sort Dictionary based on key
Load Dictionary data values into simple array
Load array into application variable

To get the random stuff:
randomize a number from 0 to array.length -1
response.write array(newRandomNumber)

mattglet

11:41 pm on Nov 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i ended up using the FSO method, and wound up making a pretty powerful tool using the ASP content rotator. dynamic entries, updateable weights, etc. it turned out nice. only a couple more features to add to it.

thanks for everyone's help.

-Matt