成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

文本分析了4000萬條Stack Overflow討論帖,這些是程序員最推薦的編程書(附代碼)

大數據 數據分析 前端
程序員們都看什么書?他們會向別人推薦哪些書?本文作者分析了Stack Overflow上的4000萬條問答,找出了程序員們最常討論的書,同時非??犊毓_了數據分析代碼。讓我們來看看作者是怎么說的吧。

程序員們都看什么書?他們會向別人推薦哪些書?

本文作者分析了Stack Overflow上的4000萬條問答,找出了程序員們最常討論的書,同時非??犊毓_了數據分析代碼。讓我們來看看作者是怎么說的吧。

尋找下一本值得讀的編程書是一件很難,而且有風險的事情。

作為一個開發者,你的時間是很寶貴的,而看書會花費大量的時間。這時間其實你本可以用來去編程,或者是去休息,但你卻決定將其用來讀書以提高自己的能力。

所以,你應該選擇讀哪本書呢?我和同事們經常討論看書的問題,我發現我們對于書的看法相差很遠。

幸運的是,Stack Exchange(程序員最常用的IT技術問答網站Stack Overflow的母公司)發布了他們的問答數據。用這些數據,我找出了Stack Overflow上4000萬條問答里,被討論最多的編程書籍,一共5720本。

在這篇文章里,我將詳細介紹數據獲取及分析過程,附有代碼。

文本分析了4000萬條Stack Overflow討論帖,這些是程序員最推薦的編程書(附代碼)

我開發了dev-books.com來展示書籍推薦排序

文本分析了4000萬條Stack Overflow討論帖,這些是程序員最推薦的編程書(附代碼)

讓我們放大看看這些最受歡迎的書

 

  • “被推薦次數最多的書是Working Effectively with Legacy Code《修改代碼的藝術》,其次是Design Pattern: Elements of Reusable Object-Oriented Software《設計模式:可復用面向對象軟件的基礎》。
  • 雖然它們的名字聽起來枯燥無味,但內容的質量還是很高的。你可以在每種標簽下將這些書依據推薦量排序,如JavaScript, C, Graphics等等。這顯然不是書籍推薦的終極方案,但是如果你準備開始編程或者提升你的知識,這是一個很好的開端。”

——來自Lifehacker.com的評論

獲取和輸入數據

我從archive.org抓取了Stack Exchange的數據。(https://archive.org/details/stackexchange)

從最開始我就意識到用最常用的方式(如 myxml := pg_read_file(‘path/to/my_file.xml’))輸入48GB的XML文件到一個新建立的數據庫(PostgreSQL)是不可能的,因為我沒有48GB的RAM在我的服務器上,所以我決定用SAX程序。

所有的值都被儲存在這個標簽之間,我用Python來提取這些值:

  1. def startElement(self, name, attributes):  
  2.  if name == ‘row’:  
  3.  self.cur.execute(“INSERT INTO posts (Id, Post_Type_Id, Parent_Id, Accepted_Answer_Id, Creation_Date, Score, View_Count, Body, Owner_User_Id, Last_Editor_User_Id, Last_Editor_Display_Name, Last_Edit_Date, Last_Activity_Date, Community_Owned_Date, Closed_Date, Title, Tags, Answer_Count, Comment_Count, Favorite_Count) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)”,  
  4.  (  
  5.  (attributes[‘Id’] if ‘Id’ in attributes else None),  
  6.  (attributes[‘PostTypeId’] if ‘PostTypeId’ in attributes else None),  
  7.  (attributes[‘ParentID’] if ‘ParentID’ in attributes else None),  
  8.  (attributes[‘AcceptedAnswerId’] if ‘AcceptedAnswerId’ in attributes else None),  
  9.  (attributes[‘CreationDate’] if ‘CreationDate’ in attributes else None),  
  10.  (attributes[‘Score’] if ‘Score’ in attributes else None),  
  11.  (attributes[‘ViewCount’] if ‘ViewCount’ in attributes else None),  
  12.  (attributes[‘Body’] if ‘Body’ in attributes else None),  
  13.  (attributes[‘OwnerUserId’] if ‘OwnerUserId’ in attributes else None),  
  14.  (attributes[‘LastEditorUserId’] if ‘LastEditorUserId’ in attributes else None),  
  15.  (attributes[‘LastEditorDisplayName’] if ‘LastEditorDisplayName’ in attributes else None),  
  16.  (attributes[‘LastEditDate’] if ‘LastEditDate’ in attributes else None),  
  17.  (attributes[‘LastActivityDate’] if ‘LastActivityDate’ in attributes else None),  
  18.  (attributes[‘CommunityOwnedDate’] if ‘CommunityOwnedDate’ in attributes else None),  
  19.  (attributes[‘ClosedDate’] if ‘ClosedDate’ in attributes else None),  
  20.  (attributes[‘Title’] if ‘Title’ in attributes else None),  
  21.  (attributes[‘Tags’] if ‘Tags’ in attributes else None),  
  22.  (attributes[‘AnswerCount’] if ‘AnswerCount’ in attributes else None),  
  23.  (attributes[‘CommentCount’] if ‘CommentCount’ in attributes else None),  
  24.  (attributes[‘FavoriteCount’] if ‘FavoriteCount’ in attributes else None)  
  25.  )  
  26.  ); 

在數據輸入進行了三天之后(有將近一半的XML在這段時間內已經被導入了),我發現我犯了一個錯誤:我把“ParentId”寫成了“ParentID”。

但這個時候,我不想再多等一周,所以把處理器從AMD E-350 (2 x 1.35GHz)換成了Intel G2020 (2 x 2.90GHz),但這并沒能加速進度。

下一個決定——批量輸入:

  1. class docHandler(xml.sax.ContentHandler):  
  2.  def __init__(self, cusor):  
  3.  self.cusor = cusor;  
  4.  self.queue = 0;  
  5.  self.output = StringIO();  
  6.    def startElement(self, name, attributes):  
  7.  if name == ‘row’:  
  8.  self.output.write(  
  9.  attributes[‘Id’] + '\t` +   
  10.  (attributes[‘PostTypeId’] if ‘PostTypeId’ in attributes else '\\N') + '\t' +   
  11.  (attributes[‘ParentId’] if ‘ParentId’ in attributes else '\\N') + '\t' +   
  12.  (attributes[‘AcceptedAnswerId’] if ‘AcceptedAnswerId’ in attributes else '\\N') + '\t' +   
  13.  (attributes[‘CreationDate’] if ‘CreationDate’ in attributes else '\\N') + '\t' +   
  14.  (attributes[‘Score’] if ‘Score’ in attributes else '\\N') + '\t' +   
  15.  (attributes[‘ViewCount’] if ‘ViewCount’ in attributes else '\\N') + '\t' +   
  16.  (attributes[‘Body’].replace('\\', '\\\\').replace('\n', '\\\n').replace('\r', '\\\r').replace('\t', '\\\t') if ‘Body’ in attributes else '\\N') + '\t' +   
  17.  (attributes[‘OwnerUserId’] if ‘OwnerUserId’ in attributes else '\\N') + '\t' +   
  18.  (attributes[‘LastEditorUserId’] if ‘LastEditorUserId’ in attributes else '\\N') + '\t' +   
  19.  (attributes[‘LastEditorDisplayName’].replace('\n''\\n') if ‘LastEditorDisplayName’ in attributes else '\\N') + '\t' +   
  20.  (attributes[‘LastEditDate’] if ‘LastEditDate’ in attributes else '\\N') + '\t' +   
  21.  (attributes[‘LastActivityDate’] if ‘LastActivityDate’ in attributes else '\\N') + '\t' +   
  22.  (attributes[‘CommunityOwnedDate’] if ‘CommunityOwnedDate’ in attributes else '\\N') + '\t' +   
  23.  (attributes[‘ClosedDate’] if ‘ClosedDate’ in attributes else '\\N') + '\t' +   
  24.  (attributes[‘Title’].replace('\\', '\\\\').replace('\n', '\\\n').replace('\r', '\\\r').replace('\t', '\\\t') if ‘Title’ in attributes else '\\N') + '\t' +   
  25.  (attributes[‘Tags’].replace('\n''\\n') if ‘Tags’ in attributes else '\\N') + '\t' +   
  26.  (attributes[‘AnswerCount’] if ‘AnswerCount’ in attributes else '\\N') + '\t' +   
  27.  (attributes[‘CommentCount’] if ‘CommentCount’ in attributes else '\\N') + '\t' +   
  28.  (attributes[‘FavoriteCount’] if ‘FavoriteCount’ in attributes else '\\N') + '\n'  
  29.  );  
  30.  self. 

StringIO讓你可以用一個文件作為變量來執行copy_from這個函數,這個函數可以執行COPY(復制)命令。用這個方法,執行所有的輸入過程只需要一個晚上。

好,是時候創建索引了。理論上,GiST Indexes會比GIN慢,但它占用更少的空間,所以我決定用GiST。又過了一天,我得到了70GB的加了索引的數據。

在試了一些測試語句后,我發現處理它們會花費大量的時間。至于原因,是因為Disk IO需要等待。使用SSD GOODRAM C40 120Gb會有很大提升,盡管它并不是目前最快的SSD。

我創建了一組新的PostgreSQL族群:

  1. initdb -D /media/ssd/postgresq/data 

然后確認改變路徑到我的config服務器(我之前用Manjaro OS):

  1. vim /usr/lib/systemd/system/postgresql.service  
  2. Environment=PGROOT=/media/ssd/postgres 
  3. PIDFile=/media/ssd/postgres/data/postmaster.pid 

重新加載config并且啟動postgreSQL:

  1. systemctl daemon-reload postgresql systemctl start 
  2. postgresql 

這次輸入數據用了幾個小時,但我用了GIN(來添加索引)。索引在SSD上占用了20GB的空間,但是簡單的查詢僅花費不到一分鐘的時間。

從數據庫提取書籍

數據全部輸入之后,我開始查找提到這些書的帖子,然后通過SQL把它們復制到另一張表:

  1. CREATE TABLE books_posts AS SELECT * FROM posts WHERE body LIKE ‘%book%’”; 

下一步是找的對應帖子的連接:

  1. CREATE TABLE http_books AS SELECT * posts WHERE body LIKE ‘%http%’”; 

但這時候我發現StakOverflow代理的所有鏈接都如下所示:

  1. rads.stackowerflow.com/[$isbn]/ 

于是,我建立了另一個表來保存這些連接和帖子:

  1. CREATE TABLE rads_posts AS SELECT * FROM posts WHERE body LIKE ‘%http://rads.stackowerflow.com%'"; 

我使用常用的方式來提取所有的ISBN(國際標準書號),并通過下圖方式提取StackOverflow的標簽到另外一個表:

  1. regexp_split_to_table 

當我有了最受歡迎的標簽并且做了統計后,我發現不同標簽的前20本提及次數最多的書都比較相似。

我的下一步:改善標簽。

方法是:在找到每個標簽對應的前20本提及次數最多的書之后,排除掉之前已經處理過的書。因為這是一次性工作,我決定用PostgreSQL數組,編程語言如下:

  1. SELECT *  
  2.  , ARRAY(SELECT UNNEST(isbns) EXCEPT SELECT UNNEST(to_exclude ))  
  3.  , ARRAY_UPPER(ARRAY(SELECT UNNEST(isbns) EXCEPT SELECT UNNEST(to_exclude )), 1)   
  4.  FROM (  
  5.  SELECT *  
  6.  , ARRAY[‘isbn1’, ‘isbn2’, ‘isbn3’] AS to_exclude   
  7.  FROM (  
  8.  SELECT   
  9.  tag  
  10.  , ARRAY_AGG(DISTINCT isbn) AS isbns  
  11.  , COUNT(DISTINCT isbn)   
  12.  FROM (  
  13.  SELECT *   
  14.  FROM (  
  15.  SELECT   
  16.  it.*  
  17.  , t.popularity   
  18.  FROM isbn_tags AS it   
  19.  LEFT OUTER JOIN isbns AS i on i.isbn = it.isbn   
  20.  LEFT OUTER JOIN tags AS t on t.tag = it.tag   
  21.  WHERE it.tag in (  
  22.  SELECT tag   
  23.  FROM tags   
  24.  ORDER BY popularity DESC   
  25.  LIMIT 1 OFFSET 0  
  26.  )   
  27.  ORDER BY post_count DESC LIMIT 20  
  28.  ) AS t1   
  29.  UNION ALL  
  30.  SELECT *   
  31.  FROM (  
  32.  SELECT   
  33.  it.*  
  34.  , t.popularity   
  35.  FROM isbn_tags AS it   
  36.  LEFT OUTER JOIN isbns AS i on i.isbn = it.isbn   
  37.  LEFT OUTER JOIN tags AS t on t.tag = it.tag   
  38.  WHERE it.tag in (  
  39.  SELECT tag   
  40.  FROM tags   
  41.  ORDER BY popularity DESC   
  42.  LIMIT 1 OFFSET 1  
  43.  )   
  44.  ORDER BY post_count   
  45.  DESC LIMIT 20  
  46.  ) AS t2   
  47.  UNION ALL  
  48.  SELECT *   
  49.  FROM (  
  50.  SELECT   
  51.  it.*  
  52.  , t.popularity   
  53.  FROM isbn_tags AS it   
  54.  LEFT OUTER JOIN isbns AS i on i.isbn = it.isbn   
  55.  LEFT OUTER JOIN tags AS t on t.tag = it.tag   
  56.  WHERE it.tag in (  
  57.  SELECT tag   
  58.  FROM tags   
  59.  ORDER BY popularity DESC   
  60.  LIMIT 1 OFFSET 2  
  61.  )   
  62.  ORDER BY post_count DESC   
  63.  LIMIT 20  
  64.  ) AS t3   
  65.  ...  
  66.  UNION ALL  
  67.    SELECT *   
  68.  FROM (  
  69.  SELECT   
  70.  it.*  
  71.  , t.popularity   
  72.  FROM isbn_tags AS it   
  73.  LEFT OUTER JOIN isbns AS i on i.isbn = it.isbn   
  74.  LEFT OUTER JOIN tags AS t on t.tag = it.tag   
  75.  WHERE it.tag in (  
  76.  SELECT tag   
  77.  FROM tags   
  78.  ORDER BY popularity DESC   
  79.  LIMIT 1 OFFSET 78  
  80.  )   
  81.  ORDER BY post_count DESC   
  82.  LIMIT 20  
  83.  ) AS t79  
  84.  ) AS tt   
  85.  GROUP BY tag   
  86.  ORDER BY max(popularity) DESC   
  87.  ) AS ttt  
  88.  ) AS tttt   
  89.  ORDER BY ARRAY_upper(ARRAY(SELECT UNNEST(arr) EXCEPT SELECT UNNEST(la)), 1) DESC

既然已經有了所需要的數據,我開始著手建立網站。

建立網站

因為我不是一個網頁開發人員,更不是一個網絡用戶界面專家,所以我決定創建一個基于默認主題的十分簡單的單頁面app。

我創建了“標簽查找”的選項,然后提取最受歡迎的標簽,使每次查找都可以點擊相應選項來搜索。

我用長條圖來可視化搜索結果。嘗試了Hightcharts和D3(分別為兩個JavaScript數據可視化圖表庫),但是他們只能起到展示作用,在用戶響應方面還存在一些問題,而且配置起來很復雜。所以我決定用SVG創建自己的響應式圖表,為了使圖表可響應,必須針對不同的屏幕旋轉方向對其進行重繪。

 

  1. var w = $('#plot').width();  
  2.  var bars = "";var imgs = "";  
  3.  var texts = "";  
  4.  var rx = 10;  
  5.  var tx = 25;  
  6.  var max = Math.floor(w / 60);  
  7.  var maxPop = 0;  
  8.  for(var i =0; i < max; i ++){  
  9.  if(i > books.length - 1 ){  
  10.  break;  
  11.  }  
  12.  obj = books[i];  
  13.  if(maxPop < Number(obj.pop)) {  
  14.  maxPop = Number(obj.pop);  
  15.  }  
  16.  }  
  17.    for(var i =0; i < max; i ++){  
  18.  if(i > books.length - 1){  
  19.  break;  
  20.  }  
  21.  obj = books[i];  
  22.  h = Math.floor((180 / maxPop ) * obj.pop);  
  23.  dt = 0;  
  24.    if(('' + obj.pop + '').length == 1){  
  25.  dt = 5;  
  26.  }  
  27.    if(('' + obj.pop + '').length == 3){  
  28.  dt = -3;  
  29.  }  
  30.    var scrollTo = 'onclick="scrollTo(\''+ obj.id +'\'); return false;" "';  
  31.  bars += '<rect id="rect'+ obj.id +'" class="cla" x="'+ rx +'" y="' + (180 - h + 30) + '" width="50" height="' + h + '" ' + scrollTo + '>';  
  32.    bars += '<title>' + obj.name'</title>';  
  33.  bars += '</rect>';  
  34.    imgs += '<image height="70" x="'+ rx +'" y="220" href="img/ol/jpeg/' + obj.id + '.jpeg" onmouseout="unhoverbar('+ obj.id +');" onmouseover="hoverbar('+ obj.id +');" width="50" ' + scrollTo + '>';  
  35.  imgs += '<title>' + obj.name'</title>';  
  36.  imgs += '</image>';  
  37.    texts += '<text x="'+ (tx + dt) +'" y="'+ (180 - h + 20) +'" class="bar-label" style="font-size: 16px;" ' + scrollTo + '>' + obj.pop + '</text>';  
  38.  rx += 60;  
  39.  tx += 60;  
  40.  }  
  41.    $('#plot').html(  
  42.  ' <svg width="100%" height="300" aria-labelledby="title desc" role="img">'  
  43.  + ' <defs> '  
  44.  + ' <style type="text/css"><![CDATA['  
  45.  + ' .cla {'  
  46.  + ' fill: #337ab7;'  
  47.  + ' }'  
  48.  + ' .cla:hover {'  
  49.  + ' fill: #5bc0de;'  
  50.  + ' }'  
  51.  + ' ]]></style>'  
  52.  + ' </defs>'  
  53.  + ' <g class="bar">'  
  54.  + bars  
  55.  + ' </g>'  
  56.  + ' <g class="bar-images">'  
  57.  + imgs  
  58.  + ' </g>'  
  59.  + ' <g class="bar-text">'  
  60.  + texts  
  61.  + ' </g>'  
  62.  + '</svg>'); 

網頁服務失敗

 

文本分析了4000萬條Stack Overflow討論帖,這些是程序員最推薦的編程書(附代碼)

Nginx 還是 Apache?

 

當我發布了 dev-books.com這個網站之后,它有了大量的點擊。而Apache卻不能讓超過500個訪問者同時訪問網站,于是我迅速部署并將網站服務器調整為Nginx。說實在的,我對于能有800個訪問者同時訪問這個網站感到非常驚喜!

責任編輯:未麗燕 來源: 大數據文摘
相關推薦

2020-08-28 09:50:12

Java程序員語言

2014-07-16 09:34:44

2019-11-07 13:48:02

程序員技能開發者

2015-07-07 10:55:05

個人信息個人信息安全信息安全

2018-11-15 16:11:10

2019-03-25 07:14:57

程序員工程師職業

2015-04-13 14:14:18

程序員開發語言調查

2020-08-04 08:48:34

數據彈屏技術

2012-07-18 10:35:22

GitHub程序員代碼

2015-04-16 13:02:50

程序員編程選擇編程技術書

2014-11-18 15:27:17

編程

2022-07-05 12:00:18

編程語言JavascriptPython

2015-02-03 02:40:33

程序員盲人程序員

2019-12-03 10:04:18

程序員招聘開發

2015-11-12 10:23:26

老程序員編程策略

2020-10-27 11:43:29

低代碼開發工具開發

2017-12-04 23:25:24

2015-07-01 09:10:20

2020-11-19 15:12:56

程序員技能開發者

2020-05-06 08:21:37

程序員年薪能力
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产成人精品999在线观看 | 国产一区二区三区四区五区加勒比 | 国产成人在线播放 | 国产精品久久久久久久久久久新郎 | 久久久久久99 | 伊人狠狠干 | 亚洲精品久久久蜜桃 | 免费在线观看h片 | 国产成人综合在线 | 亚洲男女视频在线观看 | 国产精品一区二区三区在线 | 国内精品久久久久 | 欧美在线一区二区三区四区 | 亚洲一级毛片 | 三级av免费 | 亚洲精品中文字幕在线观看 | 岛国毛片在线观看 | 国产精品成人国产乱一区 | 国产精品日韩一区 | 国产精品久久久久久久久污网站 | 久久一级免费视频 | 在线观看视频一区二区三区 | 亚洲国产aⅴ成人精品无吗 亚洲精品久久久一区二区三区 | 中文字幕乱码亚洲精品一区 | 欧美一级高潮片免费的 | 91久久久久久久久久久久久 | 亚洲精品久久久久久下一站 | 亚洲欧美日韩电影 | 精品久久久久一区二区国产 | 天堂av在线影院 | 亚洲一区二区精品视频在线观看 | 国产精品自拍视频网站 | 美女日批免费视频 | 国产伦精品一区二区三毛 | 日本成人中文字幕在线观看 | 国产亚洲第一页 | 成人在线免费视频 | www.色综合 | 97超碰在线播放 | 天天夜碰日日摸日日澡 | 久久91 |