Edge

December 13, 2005

Health

Filed under: Life

Last week I had a holiday and as good employee I was sick all week. I had lot of fewer and diarrhea.

Worst thing about diarrhea is that you have to be very cautious all the time. You can’t really relax any moment. And you can’t really fart. So I you feel that fart is coming you must go to toilet. This takes all fun out of farting…

If I get back to more serious stuff you quite easily forget how lucky you really are. I mean that you tend to forget what a good lucky is bee healthy. BTW when you start to feel grateful about being healthy then you are getting old. But that I am - quite old and relative healthy man who enjoys occasional fart…

October 7, 2005

Being a man part II

Filed under: Life

I live at apartment building. And sometime you hear some noises from other apartments. I have never actually been annoyed about the noise, but there are some people that actually are annoyed quite easily.

Example out neighbor 1 floor down was annoyed to someone (I think he was annoyed to me) who is peeing in center of toilet to the water lock. So this water gurgle was annoying him. What a wimp! I think he is peeing sitting down like a woman.

Next morning I peed again to the center of the water lock and drew some figures with my pee stream. Then I farted and laughed out loud: ”I’m a man!” I felt good about my self all day!

Being a Man

Filed under: Life

I read an interview about a woman who said something like (or the idea was anyway):

”Women are more willing to have sex, when housework has been done and husband/man has also helped with the housework”

I’m totally against of this thought! But first I have to say; I’m not saying that men should not do housework. I’m saying that making housework is not the way to sex or making housework should be some how rewarded with sex or by making housework you get more and better sex.

No no no! First of all, I think no woman is man is sexy when he is doing housework. “You are so sexy when you hovering! I want you now!” And sex should not be reward of something and there should not be any kind of thought “I will give him / her some sex because of some nice dusting he / she made…”

Sex should be so that both want to have sex. It should not be used as a weapon or any kind of tool to achieve something.

So being a man you should notice when women tries to do this. And you must fight back! And you must say no! Sex that is a reward totally not worth of it!

So sex when there is desire for both parties! It could be so that desire comes more easily when other is not just lying on the sofa and drinking beer while other is doing all cleaning, dishes etc. But still I think that real men are not doing housework so that they would have sex. Housework can be done (and I’m also doing it), but not because you are thinking about sex (Some could argue that men are all the time thinking about sex.). When you are a man woman should want you and this leads to intimacy.

So say no to reward sex!

September 7, 2005

Wonders

Filed under: Life

It is nice watch what my son (9 months) thinks is a wonder.

Example that every object (except that dam gas balloon) that he release from he’s hand drops downwards. Actually that is so huge wonder, which he must test this many times a day.

Actually I have been noticing from my self that I take many as granted. Things that should truly make you wonder. But maybe it is easier to just accept things, than trying to figure out why.

Example if you think about gravity. From physic class the teacher says that gravity is force of attraction between all masses in the universe. Yes, but if you ask why masses attract each other. That is another question

So maybe my son is tying to solve this problem. I think he will eventually come to conclusion that it much easier to just accept the gravity. Now we are just waiting the day of acceptance. It would bee much easier for our backs…

Or if he solves the problem I would not mind it either. It would be actually nice to have one Nobel price in a family…

August 29, 2005

Happiness

Filed under: Life

I read for newspaper from interview of some reality TV-series “star”.

She had a motto something like: “I want to live a happy life baah blaah blaah…”

I started to wonder the about the happy life and what is behind it. I came about with quick thought about happiness.

You should not try to live a happy life. I mean that if you all time just think I want to live a happy life and try to find happiness in everything you do – I bet that you are not going to have a happy life. In this way you are never going to bee satisfied what you are doing. You just all the time want more “happiness”.

So how do I find happiness? Hard to say, it much easier is to say where you can’t find it (or where I can’ find it).

Just that this post would not be so pessimistic here are few things that makes me happy:
- Laughter and pure joy from Arttu.
- Love and caring from Kirsi.
- Drinking beers talking bullshit with friends.
- Achieving goals that you have set your self.
- Learning some new things.

August 25, 2005

Weighted graph in SQL.

Filed under: Programming

Have you ever tried to store hierarchies in SQL. That’s easy but, have you ever tried to do some calculation in that hierarchy. That’s bit harder.

Let’s take example situation that I have some hierarchy and some cost that should be allocated in that hierarchy. Let assume that you have an HierarchyItem that could have another item many other HierarchyItems as child of it and many parents also. Then you could have some cost allocated to that hierarchy let’s say DirectCost. You share this according to weight between the HierarchyItem connection say ConnectionShare.

Here is the class diagram of this.
Class diagram

So HierarchyItem cost is sum of direct costs and cost of items child according to share ratios.

Example if have file server and it costs are 1000 euros. Application A file usage is 80GB and Application B file usage is 120GB:

Application A has costs from file server (80 / (80 + 120)) * 1000 euros = 400 euros
Application B has costs from file server (120 / (80 + 120)) * 1000 euros = 600 euros

In this easily solved with recursion as flows (Detailed code in C#):

public float GetCost(string costType)
{
	float retval = 0;
	
	//Calculate first all direct costs
	foreach(DirectCost directCost in DirectCosts)
	{
		if(directCost.CostType.Equals(costType))
			retval += directCost.Value;
	}
	//Add all child costs to this
	foreach(ConnectionShare child in ChildConnectionShares)
	{
		retval += child.GetChildCost(costType);
	}
	return retval;
}

Problem converting this to SQL is that you can’t really do recursion in SQL. So the solution in my case was to simulate the cost in time to time. Simulation is a good solution if you don’t data bee accurate all the time.

So if you think about how you would calculate this by hand. You just would start calculating this from the bottom. First calculate those items that do not have any child’s. After that you would calculate items which child’s has been calculated all ready. And the just iterate the process.

So SQL solution comes from the same idea. First calculate all those items that have no childs and after that calculate those items which child’s has been calculated. Or if I be more precise you can calculate those items where your child count is the same as calculated child count.

So if I would have an tables HierarchyItem, ConnectionShare, DirectCost and HierarchyItemCosts.

HierarchyItem you would all the hierarchy items.

ConnectionShare would include all connections between HierarchyItems

DirectCost Table would include all direct cost related to HierarchyItem.

HierarchyItemCosts would store all the simulated costs.

Let’s assume that we already have some data in there. And go step by step…

1. Find all those items that can be calculated - those items where your child count is the same as calculated child count.

SELECT 	Parent.ID
FROM 	HierarchyItem Parent LEFT JOIN ConnectionShare Child
			ON Parent.ID = Child.ParentID
		LEFT JOIN HierarchyItemCost CalulcatedItems
			ON Child.ChildID = CalulcatedItems.HierarchyItemID
GROUP BY Parent.ID
HAVING COUNT(Child.ChildID) = COUNT(CalulcatedItems.HierarchyItemID)

2. Now Select all the items that should be calculated

SELECT 	HI.ID
FROM	HierarchyItem HI
WHERE 	HI.ID IN (Query from the step 1)

3. Add all CostTypes to calculation

SELECT 	HI.ID,
	TmpCostType. CostType
FROM	HierarchyItem HI CROSS JOIN
	(SELECT DISTINCT CostType FROM DirectCost) TmpCostType
WHERE 	HI.ID IN (Query from the step 1)

4. Add the direct cost calculation

SELECT 	HI.ID,
	TmpCostType. CostType,
	(SELECT 	COALESCE(SUM(Value),0)
	 FROM 	DirectCost
	WHERE 	HierarchyItemID = HI.ID
		AND CostType = TmpCostType.CostType) 
FROM	HierarchyItem HI CROSS JOIN
	(SELECT DISTINCT CostType FROM DirectCost) TmpCostType
WHERE 	HI.ID IN (Query from the step 1)

5. Add the child costs to calculation and helpper view.


CREATE VIEW HierarchyItemTotalShare AS
SELECT 	HI.ID,COALESCE(SUM(Share),0)
FROM 	HierarchyItem HI LEFT JOIN ConnectionShare CS
		ON HI.ID = CS.ChildID
GROUP BY HI.ID 
	
SELECT COALESCE(SUM(Child.Value * (Relation.Share/TotalShare.TotalShare) ),0)
FROM 	HierarchyItemCost Child JOIN ConnectionShare Relation
			ON Child.HierarchyItemID = Relation.ChildID
		JOIN HierarchyItemTotalShare TotalShare
			ON Child.HierarchyItemID = TotalShare.ID
 WHERE	Relation.ParentID = HI.ID
		AND Child.CostType = TmpCostType.CostType
		AND TotalShare.TotalShare <> 0

6. The final insert statement that is run until all row’s have been instered.


INSERT INTO HierarchyItemCost (HierarchyItemID,CostType,Value)
SELECT 	HI.ID,
	TmpCostType.CostType,
	--Items cost is sum of direct cost +
	(SELECT COALESCE(SUM(Value),0) FROM DirectCost WHERE HierarchyItemID = HI.ID AND CostType = TmpCostType.CostType)
		+
	--Sum of all child cost acording to share
		(SELECT COALESCE(SUM(Child.Value * (Relation.Share/TotalShare.TotalShare) ),0)
		 FROM 	HierarchyItemCost Child JOIN ConnectionShare Relation
				ON Child.HierarchyItemID = Relation.ChildID
			JOIN HierarchyItemTotalShare TotalShare
				ON Child.HierarchyItemID = TotalShare.ID
		 WHERE	Relation.ParentID = HI.ID AND Child.CostType = TmpCostType.CostType AND TotalShare.TotalShare <> 0)
	
FROM	HierarchyItem HI CROSS JOIN (SELECT DISTINCT CostType FROM DirectCost) TmpCostType
WHERE 	HI.ID IN
	–All those HierarchyItems witch childs has been calculated
	(SELECT Parent.ID
	 FROM 	HierarchyItem Parent LEFT JOIN ConnectionShare Child
			ON Parent.ID = Child.ParentID
		LEFT JOIN HierarchyItemCost CalulcatedItems
			ON Child.ChildID = CalulcatedItems.HierarchyItemID
	 GROUP BY Parent.ID
	 HAVING COUNT(Child.ChildID) = COUNT(CalulcatedItems.HierarchyItemID))
	 –Only calculate every item once
	 AND HI.ID NOT IN (SELECT HierarchyItemID FROM HierarchyItemCost)

Voilá!

If you have SqlServer you can test the solution with this script.

August 23, 2005

Not enough time

Filed under: Life

Lately I have noticed that there are not enough hours for everything.

Example where you get time study?

Here is my normal week day:

7:00 - 7:15 Wake up, shower and breakfast
7:15 - 8:15 Drive to work (or some sports)
8:15 - 12:00 Work
12:00 -12:30 Lunch
17:00 – 18:00 Back to Home
18:00 - 20:00 Supper, playing with Arttu and Kirsi and
20:00 - 21:00 Trying to make Arttu sleep (Kirsi is doing this most of the time)
21:00 - 22:00 TV and reading

So the day is quite full. So only time to study is the tv-time. That is why I have decided stop watching TV. It is so rare that something good comes from TV. Occasionally TV is nice way to relax, but most of the time it just makes you phlegmatic. But let’s see how long this decision is going to last…

August 21, 2005

Poem

Filed under: Life

Sun rises,

golden sparkling dew on a leaf.

I fart and lift my zipper.

August 18, 2005

Mobile phones

Filed under: Life

Sometimes people call me and ask: “Are you at good place to talk”. I thing this question is unnesesary, because if I’m at place that I’m not able to talk I will not answer the phone. Sometimes I did also ask this question. I was thinking that question was good behaviour, because I was bothering some one with my phoning. Now I’m thinking that this question just waists time…

BTW Would be nice to have software in your mobile that when I’m example at movie I could put movie profile on. If call comes then phone would just ingnore it and send SMS that I’m at movie…

II hate when people talk through speakers and you are not sure if you are just speaking to the person you wanted or if there are others around. So this reason I have decided following rules:

IIf answer phone and I’m using the speaker I say something like following: “Hey, can you hear me because I’m using the speaker”. This way people now that I’m using speaker and someone might be other than me might be hearing what are we talking about.

IIf there is people around I say something like “Hey, I’m here with XXX and can you hear us” or something.

So basic idea is that you should somehow inform your caller that you are using the speaker…

August 17, 2005

Hungry

Filed under: Life

After my summer holidays I decided to loose some weight, that I have gain when enjoying sun, beer and grilled food. And 100 euro bet with my brother is helping a bit.

So now I’m in two week diet and exercise camp. One thing that I can now say, that being hungry is not a good feeling. All the food smells so good…

Now it is my third day and I’m already lost some weight. Mostly water I think.

Day Food Exercise Weight
Meat week
Day1 Morning: Black coffee
Lunch: 250g chicken, salad and tomatoes
Supper: An egg, tomatoes
During the day: 3 liters of low salt mineral water
30 min walk with my son 84 kg
Day2 Morning: Black coffee and one egg
Lunch: 250g chicken, salad and tomatoes
Supper: An egg, tomatoes
During the day: 3 liters of low salt mineral water
1:45 roller-skaiting to office. 82 kg
Day3 Morning: Black coffee
Lunch: 250g chicken, salad and tomatoes
Supper: 250 g chicken, tomatoe and banana
During the day: 3 liters of low salt mineral water
1:45 roller-skaiting to office. 80,5 kg
Day4 Morning: Black coffee
Lunch: 2dl jogurth
Supper: 250 g chicken, tomatoe and banana
During the day: 3 liters of low salt mineral water
1 hour of badminton 80 kg
Day5 Morning: Black coffee
Lunch: Ann Egg, 2dl Cottage chees and 2 carrots
Supper: Spinach soup
During the day: 3 liters of low salt mineral water
1km of swimming
1 hour walk
80 kg (No weight loss.)
Easy two days
Day6 Morning: Black coffee and ryed bread with two slcie of cheese
Lunch:Chicken, feata peach sallad. Coffee and blueberry pie
Supper:Tee, two cheese sandwitch, 3 slice of blueberry pie. half a bottle of sparkling winw. Half bottel of beer
45 min walk
45 min run
No weighting.
Day7 Morning: Beacon and eggs, pancake, jougurth, Coffe, Croisant and fresh orange juice.
Lunch:mushroom soup and bread
Supper:Too much of everything!
45 min walk No weighting.
Soup week
Day8 Morning: Coffee
Lunch: -
Supper: Vegetable soup, Nachos
45 min walk No weighting.
Day9 Morning: Coffee
Lunch:-
Supper: Vegetable Soup, Bread, Nachos
1 hour badmintons
1:30 indoor climbing
No weighting.
Day10 Morning: Coffee
Lunch: Vegetable Soup, Motzarella bread
Supper: Vegetable Soup, Bread, Nachos
20 min running at gym
20 min rowing at gym
10 min cycling at gym
81 kg (That easy two days!)
Day11 Morning: Coffee
Lunch: Big chicken sallad
Supper: Vegetable Soup, Bread, Apples
None 81 kg
Day12 Morning: Coffee, Porridge, Bread
Lunch: Sushi, Tee
Supper: Vegetable Soup
1 km of swinmming
Day13 Morning: Coffee
Lunch: Vegetable Soup
Supper: Pizza, Beer and some candy
Evening: More pizza and few drinks
None 81 kg
I was the winner in the dieting competition with by brotehr!





















Get free blog up and running in minutes with Blogsome | Theme designs available here