Skip to content

Commit

Permalink
provide shopping cart
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangift committed Jul 5, 2015
1 parent 29873e4 commit 9f245fd
Show file tree
Hide file tree
Showing 3 changed files with 248 additions and 93 deletions.
36 changes: 15 additions & 21 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
font-size: 12px;
background: #fff;
margin: 45px;
margin: 10px 20px;
border-collapse: collapse;
text-align: center;
}
Expand All @@ -48,14 +48,15 @@
padding: 10px 8px;
border-bottom: 2px solid #6678b1;
}
td
td
{
color: #669;
padding: 9px 8px 0px 8px;
}
tbody tr:hover td
{
color: #009;
background: #eee;
}
td.S {
color: #FB3;
Expand All @@ -69,6 +70,9 @@
td.C {
color: #38F;
}
td.negative {
text-decoration: line-through;
}
div.facet {
margin-left:10px;
}
Expand Down Expand Up @@ -130,9 +134,10 @@
<div class='announcement'>
Nikki's wardrobe. By Ivan's workshop<br/>
服装数据来自jillhx@贴吧 20150701<br/>
Update 20150702:<br/>
Update 20150704:<br/>
<ul>
<li>衣柜已经更新到jillhx的20150701版,共计:2104,占比97.5%</li>
<li>增加了购物篮模式,可以把选中的衣服加入来估算总分以及单项得分。新功能写得急了点可能有很多bug,请多多汇报。</li>
<li>自动选择饰品的功能已经被整合入购物篮,由之前的分数排序改成类型排序。</li>
</ul>
衣服信息纠错请去<a href="http://tieba.baidu.com/p/3860789814">jillhx的新衣柜楼</a>汇报<br/>
功能错误或者有新需求请去<a href="http://tieba.baidu.com/p/3792563906">主贴</a>汇报<br/>
Expand Down Expand Up @@ -190,18 +195,19 @@
</div>
</div>
<div>
<input type="checkbox" name="inventory" value="own" onClick="refreshTable()" checked />拥有
<input type="checkbox" name="inventory" value="own" onClick="onChangeUiFilter()" checked />拥有
<span id='inventoryCount'> </span>
<input type="checkbox" name="inventory" value="missing" onClick="refreshTable()" checked /> 没有
<input type="checkbox" name="inventory" value="missing" onClick="onChangeUiFilter()" checked /> 没有
</div>
</form>
</div>
<hr>
<div id='topAccessories'>
[测试] 不要再去挑饰品了,直接用下面这些就可以了
<div id='topAccessoriesTable'>
<div id='shoppingCart'>
已选择的衣服 <input type="checkbox" id="accessoriesHelper" checked />自动选择饰品
<div id='shoppingCartTable'>
</div>
</div>
<hr>
<div id='category_container'>
</div>
<div id = "clothes"></div>
Expand All @@ -228,17 +234,5 @@
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1433922605968-0'); });
</script>
</div>
<div>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- traffic tracking -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-9395388490436466"
data-ad-slot="1321700838"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
</body>
</html>
151 changes: 130 additions & 21 deletions model.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Ivan's Workshop

var FEATURES = ["simple", "cute", "active", "pure", "cool"];

// parses a csv row into object
// Clothes: name, type, id, stars, gorgeous, simple, elegant, active, mature, cute, sexy, pure, cool, warm,extra
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Expand Down Expand Up @@ -36,10 +38,28 @@ Clothes = function(csv) {
calc: function(filters) {
var s = 0;
var self = this;
this.tmpScoreByCategory = ScoreByCategory();
for (var i in FEATURES) {
var f = FEATURES[i];
if (filters[f] && filters[f] * self[f][2] > 0) {
s += filters[f] * self[f][2];
var f = FEATURES[i];
if (filters[f]) {
var sub = filters[f] * self[f][2];
if (filters[f] > 0) {
if (sub > 0) {
this.tmpScoreByCategory.record(f, sub, 0); // matched with major
} else {
this.tmpScoreByCategory.record(f, 0, sub); // mismatch with minor
}
} else {
if (sub > 0) {
this.tmpScoreByCategory.record(f, 0, sub); // matched with minor
} else {
this.tmpScoreByCategory.record(f, sub, 0); // mismatch with major
}

}
if (sub > 0) {
s += sub;
}
}
}

Expand Down Expand Up @@ -71,6 +91,31 @@ Clothes = function(csv) {
};
}

function ScoreByCategory() {
var initial = {};
for (var c in FEATURES) {
initial[FEATURES[c]] = [0, 0];
}
return {
scores: initial,
// score: positive - matched, negative - no matched
record: function(category, major, minor) {
this.scores[category] = [major, minor];
},
add: function(other) {
for (var c in other.scores) {
this.scores[c][0] += other.scores[c][0];
this.scores[c][1] += other.scores[c][1];
}
},
round: function() {
for (var c in this.scores) {
this.scores[c][0] = Math.round(this.scores[c][0]);
this.scores[c][1] = Math.round(this.scores[c][1]);
}
}
};
}

function MyClothes() {
return {
Expand Down Expand Up @@ -152,6 +197,87 @@ var clothesSet = function() {
return ret;
}();

var shoppingCart = {
cart: {},
totalScore: fakeClothes(this.cart),
clear: function() {
this.cart = {};
},
contains: function(c) {
return this.cart[c.type.type] == c;
},
remove: function(c) {
delete this.cart[c];
},
putAll: function(clothes) {
for (var i in clothes) {
this.put(clothes[i]);
}
},
put: function(c) {
this.cart[c.type.type] = c;
},
toList: function(sortBy) {
var ret = [];
for (var t in this.cart) {
ret.push(this.cart[t]);
}
return ret.sort(sortBy);
},
calc: function(criteria) {
for (var c in this.cart) {
this.cart[c].calc(criteria);
}
// fake a clothes
this.totalScore = fakeClothes(this.cart);
}
};

function accScore(total, items) {
if (items <= 3) {
return total;
}
return total * (1 - 0.06 * (items-3));
}

function fakeClothes(cart) {
var totalScore = 0;
var totalAccessories = 0;
var totalScoreByCategory = ScoreByCategory();
var totalAccessoriesByCategory = ScoreByCategory();
var numAccessories = 0;
for (var c in cart) {
if (c.split('-')[0] == "饰品") {
totalAccessories += cart[c].tmpScore;
totalAccessoriesByCategory.add(cart[c].tmpScoreByCategory);
numAccessories ++;
} else {
totalScore += cart[c].tmpScore;
totalScoreByCategory.add(cart[c].tmpScoreByCategory);
}
}
totalScore += accScore(totalAccessories, numAccessories);
for (var c in totalAccessoriesByCategory.scores) {
totalAccessoriesByCategory.scores[c][0] = accScore(totalAccessoriesByCategory.scores[c][0],
numAccessories);
totalAccessoriesByCategory.scores[c][1] = accScore(totalAccessoriesByCategory.scores[c][1],
numAccessories);
}
totalScoreByCategory.add(totalAccessoriesByCategory);
totalScoreByCategory.round();

var scores = totalScoreByCategory.scores;
return {
name: '总分',
tmpScore: Math.round(totalScore),
toCsv: function() {
return [this.name, '', '', scores.simple[0], scores.simple[1], scores.cute[0], scores.cute[1],
scores.active[0], scores.active[1], scores.pure[0], scores.pure[1], scores.cool[0],
scores.cool[1], '', ''];
}
};
}

function realRating(a, b, type) {
real = a ? a : b;
symbol = a ? 1 : -1;
Expand Down Expand Up @@ -210,7 +336,7 @@ function getCookie(c_name) {
return unescape(document.cookie.substring(c_start,c_end))
}
}
return ""
return "";
}

function setCookie(c_name,value,expiredays) {
Expand All @@ -230,21 +356,4 @@ function save() {
setCookie("mine2", txt, 3650);
}
return myClothes;
}

function backfillTag() {
for (var type in clothesSet) {
var cs = clothesSet[type];
for (var id in cs) {
var c = cs[id];
if (c.source.indexOf("定") >= 0) {
var origin = c.source.substring(1, 4);
if (cs[origin]) {
if (c.tags.length == 0) {
c.tags = cs[origin].tags;
}
}
}
}
}
}
Loading

0 comments on commit 9f245fd

Please sign in to comment.