On Raspberry PI, develop a service to periodically match records in two XML files. Then call a player API to force play a screen.
1. A sample profile file is,
2. A sample media content file is,
<xml><Playlist PlayerId="1000001"><Content id="23" type="image" location="/Content/a2/1w3ewsed.jpg" ageMin="23" ageMax="35" gender="male" likes="music;movies" /><Content id="237" type="image" location="/Content/0f/gtfrddsed.jpg
3. Profiles in profile file is appended to it all the time from other services. For one matching, only use the profiles available within a pre-defined period (default to 10 seconds). Eg, if this service runs every 10 seconds, only use the profiles that have timestamp within last 10 seconds. For better performance, older profiles need to be removed from this profile file or archived to another logging file.
4. Matching logic – find the majority of the profiles’ attributes.
Firstly, we get each profile against each ad. The ad scores 1 point if any attributes matches, eg, an ad with targeting to male will score 1 when comparing to a guy's profile but scores 0 when comparing to a girl's profile. Same for age and likes (one like counts as 1. so each like is weighted equivalent to gender or age).
Secondly, we get a sum of all scores from all profiles for each ad.
Lastly, we try to decide the frequency, which is (total score of current ad / sum of all scores). Then we get a thread same random with this calculated frequency to finally decide which ad to show.
5. Where there is a match, call a Perl command with screen ID to force play this particular screen.
6. Reporting – send the following scenarios back to server for reporting purposes
a. Send all expired profiles to a remote server via web service
b. Send every matching result back to a remote server via web service
c. Sending better runs under a separate thread