Proposal for Declarative Preference Conditions/Proposal for Priority

From wiki.gpii
Revision as of 13:21, 1 August 2014 by CStrobbe (talk | contribs) (wikilink)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
note: this is a WiP page, nothing here should be treated as agreed upon by the community

Proposal for Declarative Preference Conditions


Borrowing the use case "Homer" from the architectural notes from Crete (though in that wiki page the declarative preference conditions are expressed slightly differently).


Example of what could happen if we don't make priorities mandatory

Starting point

Homer Has low vision so generally prefer an increased font-size (15) on his system. At night, his eyes get tired so he would REQUIRES an even further increased font size (18) after 18:00. [require vs prefer, simple context set]


{
    "contexts": {
        "gpii-default": {
            "name": "Default preferences",
            "preferences": {
                "http://registry.gpii.net/common/fontSize": 15
            }
        },

        "nighttime": {
           "name": "Nighttime",

           "preferences": {
               "http://registry.gpii.net/common/fontSize": 18
           },

           "conditions": [
               
                   
                       {
                           "type": "http://registry.gpii.net/conditions/timeOfDay",
                           "range": {
                               "start": "20:00",
                               "end": "08:00"
                           }
                       }
                   
               
           ],
        }
    },

    "policies": {}
}


New conditions

At a later point, Homer decides that under unfavourable lighting conditions he wants the fontsize to be 24 pts. Also he decides that when he's at home he wants the fontsize to be 12 pts (for his own reasons, maybe he's stating that when he feels more comfortable he wants to capture more information at a glance paying the drawback of reduced accessibility) so the profile now looks like:

{
    "contexts": {
        "gpii-default": {
            "name": "Default preferences",
            "preferences": {
                "http://registry.gpii.net/common/fontSize": 15
            }
        },

        "nighttime": {
           "name": "Nighttime",

           "preferences": {
               "http://registry.gpii.net/common/fontSize": 18
           },

           "conditions": [
               
                   
                       {
                           "type": "http://registry.gpii.net/conditions/timeOfDay",
                           "range": {
                               "start": "20:00",
                               "end": "08:00"
                           }
                       }
                   
               
           ],
        },
		"at-home": {
           "name": "When I'm at home",

           "preferences": {
               "http://registry.gpii.net/common/fontSize": 12
           },

           "conditions": [
               
                   
                       {
                           "type": "http://registry.gpii.net/conditions/location",
                           "gps": {
                               "latitude": 39.47825,
                               "longitude": -6.34186
                           }
                       }
                   
               
           ],
        },
		"randomname1234": {
           "name": "Too bright",

           "preferences": {
               "http://registry.gpii.net/common/fontSize": 24
           },

           "conditions": [
               
                   
                       {
                           "type": "http://registry.gpii.net/conditions/luminance",
                           "range": {
                               "start": 900,
                               "end": "unbounded"
                           }
                       }
                   
               
           ],
        }
		
    },

    "policies": {}
}


Conflict situation

Homer it's at home, it's 10pm and someone pointed a luxo reading lamp towards his computer reaching 1200 lux.

As stated in [1] the default is overriden as soon as at least one of the contexts is satisfied, but we still have to decide between 12,18 and 24 to be the final fontsize for Homer.


[1] Please someone point to the wiki page where this can be seen.


How mandatory priorities can help

salience
default value: 0
type: integer
Each rule has an integer salience attribute which defaults to zero and can be negative or positive. Salience is a form of priority where rules with higher salience values are given higher priority when ordered in the Activation queue.

(from http://docs.jboss.org/drools/release/5.2.0.Final/drools-expert-docs/html/ch05.html)

This concept is similar to pin-priority in debian (http://jaqque.sbih.org/kplug/apt-pinning.html )

If by chance two actions get the same salience, it should be considered as random. The MM is not responsible of tangling the rules in a specific order (that frees the system for the stress of an order-based priority that is needed in other parts of the project)

Alongside with the minirules the MM shall send to the MMM the operation mode in two parameters (defaults|current) and (salience|all).

  • Defaults: the set of settings returns to the last setted without taking into account the incremental changes that could have been occurring thanks to context changes.
  • Current: the set of settings that serves as base for the new changes is the one that is currently being used by the user, thus respecting the last incremental changes.
  • Salience: only the rule with higher salience is applied in this beat.
  • All: all the matching rules are applied. If two rules change the same setting, the rule with higher salience wins.


The following table shows different examples of results for all of these combinations:

possible results

defaults

current

m3 rules that make true the conditions<o:p></o:p>

salience

default+salience

current+salience

default+all

current+all

a=1,
b=2

a=3,
j=12

a=4

1

a=1,
 b=2,
d=114

a=3,
j=12,
d=114

a=4,
b=2,
c=7,
d=114

a=4,
c=7,
j=12,
d=114

c=7,
d=8

2

d=114

3

How not to bother the user with stating the priority

  1. First 'context'(conditions then actions) stated by the user starts with priority 1024
  2. When the user creates another context, the new one is assigned 1025 as priority, taking as granted that the fresher information is the one that the user wants to see applied.
  3. A system for letting the user rearrange the contexts is provided by the PMT, eg
    1. a visual way to sort contexts via drag&drop (eg asana tasks or trello cards)
    2. a inputbox to let the user directly state a number
      1. if we keep with the 'reserved' range of numbers for user-stated conditions, then we can opt to add 1024 to the range 1.. introduced by the user, or we can let the user know this fact.


In that way, the assignment of priorities is purely optional from the user perspective whereas it's still being always done from the system perspective.