Skip to content

Commit

Permalink
格式化回滚
Browse files Browse the repository at this point in the history
  • Loading branch information
snowtraces committed Mar 25, 2020
1 parent 3d670be commit e0f1624
Show file tree
Hide file tree
Showing 19 changed files with 226,086 additions and 109,597 deletions.
20,710 changes: 10,355 additions & 10,355 deletions ci/ci.song.0.json

Large diffs are not rendered by default.

18,624 changes: 9,312 additions & 9,312 deletions ci/ci.song.1000.json

Large diffs are not rendered by default.

19,880 changes: 9,940 additions & 9,940 deletions ci/ci.song.12000.json

Large diffs are not rendered by default.

20,556 changes: 10,278 additions & 10,278 deletions ci/ci.song.13000.json

Large diffs are not rendered by default.

23,296 changes: 11,648 additions & 11,648 deletions ci/ci.song.15000.json

Large diffs are not rendered by default.

22,694 changes: 11,347 additions & 11,347 deletions ci/ci.song.18000.json

Large diffs are not rendered by default.

16,662 changes: 8,331 additions & 8,331 deletions ci/ci.song.19000.json

Large diffs are not rendered by default.

18,818 changes: 9,409 additions & 9,409 deletions ci/ci.song.5000.json

Large diffs are not rendered by default.

18,822 changes: 9,411 additions & 9,411 deletions ci/ci.song.6000.json

Large diffs are not rendered by default.

20,156 changes: 10,078 additions & 10,078 deletions ci/ci.song.7000.json

Large diffs are not rendered by default.

18,976 changes: 9,488 additions & 9,488 deletions ci/ci.song.8000.json

Large diffs are not rendered by default.

20,980 changes: 20,980 additions & 0 deletions ci/data.sql

Large diffs are not rendered by default.

20,980 changes: 20,980 additions & 0 deletions ci/data1.sql

Large diffs are not rendered by default.

161 changes: 161 additions & 0 deletions ci/fun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/**
* 异步请求
*/
const get = function (url, data) {
return new Promise((resolve, reject) => {
var xhr = new XMLHttpRequest();
if (data) {
url = url + '?' + Object.keys(data).map(key => `${key}=${data[key]}`).join('&')
}
xhr.open('GET', url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status >= 200 && xhr.status < 400) {
let result = JSON.parse(xhr.responseText)
resolve(result);
} else {
reject ? reject() : errorMsg(result.msg || '失败')
}
}
}
xhr.send(null);
})
}
const post = function (url, data) {
return new Promise((resolve, reject) => {
var xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status >= 200 && xhr.status < 400) {
let result = JSON.parse(xhr.responseText)
resolve(result);
successMsg(result.msg || '成功')
} else {
reject ? reject() : errorMsg(result.msg || '失败')
}
}
}
xhr.send(json2FormData(data));
})
}

const json2FormData = function (data) {
let formData = new FormData()
for (let key in data) {
formData.set(key, data[key])
}
return formData
}


Array.prototype.getMost = function(){
var obj = this.reduce((p,n) =>(p[n]++ ||(p[n] = 1),(p.max=p.max>=p[n]?p.max:p[n]), (p.key=p.max>p[n]?p.key:n), p), {});
return obj.key;
}
let result = {}
get('http://127.0.0.1:8880/%E8%AF%8D%E7%89%8C%E5%90%8D%E5%BD%92%E7%B1%BB%E9%95%BF%E5%BA%A6%E5%AF%B9%E6%AF%94.json').then(r => {
let keys = Object.keys(r);
keys.forEach(k => {
let v = r[k]
let dataList = []
let _keys = Object.keys(v);
_keys.forEach(_k => {
let _o = v[_k]
dataList = dataList.concat(Object.keys(_o).map(__k => _o[__k]))
});

result[k] = dataList.getMost()
})
})


get('http://127.0.0.1:8880/%E8%AF%8D%E7%89%8C%E5%90%8D%E5%BD%92%E7%B1%BB%E9%95%BF%E5%BA%A6%E5%AF%B9%E6%AF%94.json').then(r => {
let keys = Object.keys(r);
keys.forEach(k => {
let standard = result[k]
let v = r[k]
let _keys = Object.keys(v);
_keys.forEach(_k => {
let _o = v[_k]
Object.keys(_o).map(__k => {
let __v = _o[__k]
if (__v === standard) {
delete _o[__k]
}
})
if (Object.keys(_o).length === 0) {
delete v[_k]
}
});

if (Object.keys(v).length === 0) {
delete r[k]
}
if (r[k]) {
r[k][-1] = standard
}

})

console.log(JSON.stringify(r))
})

function diff(standard, source) {
let result = source
let len_1 = standard.length
let len_2 = source.length
if (len_1 !== len_2 || standard.indexOf('-') !== source.indexOf('-')) {
return `[?]${source}`
}

let offset = 1;
for (let i = 0; i < len_1; i++) {
let v = standard[i]
let _v = source[i]
if (v !== _v) {
let _array = result.split('')
_array.splice(i+offset, 0, `[${v}]`)
result = _array.join('')
offset = offset + 3
}
}
return result;
}


get('http://127.0.0.1:8880/有问题的对象.json').then(r => {
let keys = Object.keys(r);
keys.forEach(k => {
let v = r[k]
let standard = v[-1]
let _keys = Object.keys(v);
_keys.forEach(_k => {
let _o = v[_k]
Object.keys(_o).map(__k => {
let __v = _o[__k]
if (__v !== standard) {
// 对比差异
_o[__k] = diff(standard, __v)
}
})
});
})

console.log(JSON.stringify(r))
})


/**
* sql 生成
*/
let result = ''
for(let i = 0; i < 22; i++) {
get(`http://127.0.0.1:8880/ci.song.${i * 1000}.json`).then(r => {
result += r.map((item, idx) => {
return `insert into json_ci (author, paragraphs, rhythmic, fileIdx, idx, tags) values ('${item.author}', '${item.paragraphs.join('\\n')}', '${item.rhythmic}', ${i}, ${idx}, '${item.tags ? item.tags.join() : ""}');`
}).join('\n')
})
}
console.log(result)

Loading

0 comments on commit e0f1624

Please sign in to comment.