# KEHOME/knowledge/rhm/applications/RealEstate/ContextPipe.html # Sep/1/2008 Sep/24/2008 # MLS example - average price of 3 BR homes sold

1. MLS input data

The input REL file (mls.rel.html) was generated by saving the realtor's HTML "spreadsheet" file (mls.html) as a TXT file (mls.txt), copying to a REL file, and using "vi" to do some simple edits.

2. Using a single context

Because mKR relations have a context-dependent "meaning", I can use the Home properties to filter the homes, and do the calculation in a single context. Note that home3 is a species of Home.
	at view = RealEstate;
	do read from mls.rel.html done;
	home3 is Home with Bedrooms = 3, Status = Sold;
	list3 := ? has Bedrooms = 3, Status = Sold;
	do move od $list3 from Home to home3 done;
	average3 := do average price od home3 done;
	do print od "average price of 3 BR homes sold = $average3" done;

3. Using a context pipe

Alternatively, I can create a new context by filtering the mls relation, and do the calculation in this new context. Note that mls3 is a subrelation of mls.
	at view = RealEstate;
	{ do read from mls.rel.html done; }
	| { mls3 := do select from mls with Bedrooms = 3, Status = Sold done; }
	| {
	    average3 := do average price od Price from mls3 done;
	    do print od "average price of 3 BR homes sold = $average3" done;
	  };