用戶畫像產品化——從零開始搭建實時用戶畫像(六)

在開發好用戶標籤以後,如何將標籤應用到實際其實是一個很重要的問題。只有做好產品的設計才能讓標籤發揮真正的價值,本文將介紹用戶畫像的產品化過程。

一、標籤展示

首先是標籤展示功能,這個主要供業務人員和研發人員使用,是為了更直觀的看見整個的用戶標籤體系。

不同的標籤體系會有不同的層級,那麼這個頁面的設計就需要我們展示成樹狀的結構,方便以後的擴展。

在最後一個層級,比如自然性別,可以設計一個統計頁面,在進入頁面后,可以展示相應的數據統計情況,

可以更直觀看見標籤中值得比例,也可以為業務提供好的建議,另外可以對標籤的具體描述進行展示,起到一個說明的作用,還可以展示標籤按天的波動情況,觀察標籤的變化情況。

這一部分的數據來源呢?之前也提到過,這些標籤的元數據信息都存在mysql中,方便我們查詢。

所以樹狀圖和標籤描述信息需要去mysql中獲取,而比例等圖表數據則是從Hbase,Hive中查詢獲取的,當然也有直接通過ES獲取的。但是每天的標籤歷史波動情況,還是要通過每天跑完標籤后存在mysql中作為歷史記錄進行展示。

二 、標籤查詢

這一功能可以提供給研發人員和業務人員使用。

標籤查詢功能其實就是對用戶進行全局畫像的過程,對於一個用戶的全量標籤信息,我們是需要對其進行展示的。

輸入用戶id后,可以查看該用戶的屬性信息、行為信息、風控屬性等信息。從多方位了解一個具體的用戶特徵。

這些已經是標籤的具體信息了,由於是對單一id的查找,從hive中獲取會造成查詢速度的問題,所以我們更建議從Hbase或者ES中查詢獲取,這樣查詢效率和實時性都能獲得極大的提升。

三、標籤管理

這一功能是提供給研發人員使用的。

對於標籤,不能每一次新增一個標籤都進行非常大改動,這樣是非常耗費人力的,所以必須要有可以對標籤進行管理的功能。

這裏定義了標籤的基本信息,開發方式,開發人員等等,在完成標籤的開發以後,直接在此頁面對標籤進行錄入,就可以完成標籤的上線工作,讓業務人員可以對標籤進行使用。

新增和編輯標籤的頁面,可以提供下拉框或者輸入框提供信息錄入的功能。

之前已經提到過,這些標籤的元數據信息都保存在了Mysql中,只要完成對其的新增和修改就可以了。

四、用戶分群

作為用戶畫像最核心的功能,用戶分群功能。是用戶畫像與業務系統建立聯繫的橋樑,也是用戶畫像的價值所在。

這項功能主要供業務人員使用。

此功能允許用戶自定義的圈定一部分人員,圈定的規則就是對於標籤的條件約束。

在圈定好人群以後,可以對這部分人群提供與業務系統的外呼系統,客服系統,廣告系統,Push系統的交互,達到真正的精細化運營的目的。

對於標籤規則的判斷,需要將記錄好的規則存儲於Mysql中,在進行人群計算時又需要將規則解析成可計算的邏輯。不管是解析成Sql或者其他的查詢語言都難度巨大,這對於研發是一個非常大的挑戰。

在此功能中,還可以增加人群對比的功能,對不同人群的不同標籤進行圈定,對比。這對於查詢性能也是一個巨大的考驗。

但是,用戶分群功能作為用戶畫像的核心是我們必須要實現的。對於技術架構,Hbase更擅長與KV形式的查詢,對於多維度查詢性能較差,所以可以採取ES索引,在ES查詢出Hbase的Rowkey,再去查詢Hbase的方式。也有很多公司選擇整體遷移到ES中完成此項工作。那麼ES可以勝任這項工作嗎?

下一章,我們來聊一聊如何用ES來實現用戶分群,未完待續~

參考文獻

《用戶畫像:方法論與工程化解決方案》

更多實時數據分析相關博文與科技資訊,歡迎關注 “實時流式計算” 獲取用戶畫像相關資料 請關注 “實時流式計算” 回復 “用戶畫像”

本站聲明:網站內容來源於博客園,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※如何讓商品強力曝光呢? 網頁設計公司幫您建置最吸引人的網站,提高曝光率!!

網頁設計一頭霧水??該從何著手呢? 找到專業技術的網頁設計公司,幫您輕鬆架站!

※想知道最厲害的台北網頁設計公司推薦台中網頁設計公司推薦專業設計師”嚨底家”!!

※幫你省時又省力,新北清潔一流服務好口碑

※別再煩惱如何寫文案,掌握八大原則!

冰河期大氣中二氧化碳濃度為何比較低? 關鍵證據找到了

編譯:嚴融怡(胡適國小創思組科任教師)

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※想知道網站建置網站改版該如何進行嗎?將由專業工程師為您規劃客製化網頁設計後台網頁設計

※不管是台北網頁設計公司台中網頁設計公司,全省皆有專員為您服務

※Google地圖已可更新顯示潭子電動車充電站設置地點!!

※帶您來看台北網站建置台北網頁設計,各種案例分享

※別再煩惱如何寫文案,掌握八大原則!

印度海灘白色毒泡沫 釀新一波污染危機

摘錄自2019年12月02日中央通訊社報導

印度坦米爾那都省(Tamil Nadu)首府清奈(Chennai)著名的馬利納海灘(Marina Beach)今天(2日)連續第4天被白色泡沫覆蓋,造成印度新一波污染危機。

法新社報導,即使泡沫散發出陣陣刺鼻氣味,孩子們仍在海灘上的白色泡沫堆裡玩耍和自拍。漁民則被告知不要前往附近海域。醫生警告,白色泡沫可能引發皮膚問題。這些泡沫形成於每年季風季,但今年的「毒泡沫」危機特別嚴重。

坦米爾那都省污染控制局(Tamil Nadu Pollution Control Board)表示,他們正在分析泡沫樣本。這些泡沫蔓延海灘數公里。清奈印度國家海岸研究中心(National Centre for Coastal Research)科學家米西拉(Pravakar Mishra)指出:「民眾接觸泡沫絕對不好,但他們就是不了解風險。」

根據米西拉的說法,大部分泡沫是由洗滌劑殘留物和其他廢棄物混合而成。

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※如何讓商品強力曝光呢? 網頁設計公司幫您建置最吸引人的網站,提高曝光率!!

網頁設計一頭霧水??該從何著手呢? 找到專業技術的網頁設計公司,幫您輕鬆架站!

※想知道最厲害的台北網頁設計公司推薦台中網頁設計公司推薦專業設計師”嚨底家”!!

※幫你省時又省力,新北清潔一流服務好口碑

※別再煩惱如何寫文案,掌握八大原則!

儲電技術與成本 抑制印度煤電成長的關鍵 | 解讀《 2019年世界能源展望》報告2/3

環境資訊中心外電;姜唯 翻譯;林大利 審校;稿源:Carbon Brief 前言:國際能源署(IEA)11月13日發表2019年《世界能源展望》報告。810頁報告的特點在於「承諾政策情境」(Stated Policies Scenario, STEPS),反映政府已經說出口的政策的效果──風能和太陽能的激增將使再生能源滿足全球能源需求的大部分成長。但是煤炭的平穩發展,加上對石油和天然氣的需求不斷增加,全球排放量在到2040年的展望期內將繼續上升。 相對地,報告的「永續發展情境」(Sustainable Development Scenario, SDS)描繪出有50%機率將升溫限制在1.65°C內所需的條件,IEA表示這是「完全符合巴黎協定」的情況──SDS需要投資「大量重新分配」,從化石燃料轉向效率和再生能源、淘汰全球約一半的燃煤電廠,以及全球經濟的其他變化。

二氧化碳排放量

()在STEPS之下,全球來自能源的碳排放量將在2018年創紀錄後繼續上升,本世紀很可能升溫2.7°C以上。 下表中的黑色虛線表示此排放軌跡。

相反地,SDS(紅色粗線)之下碳排迅速下降,比2010年還下降17%,2040年下降48%,2050年下降68%。IEA說,如此可在2070年實現淨零排放,並且有50%的機會將升溫限制在1.65°C,或66%的機會停在1.8°C。

這條軌跡的積極度比大多數1.5°C途徑要低,升溫沒有或是僅一小段時間超標(下圖中的黃線)。 政府間氣候變遷專門委員會(IPCC)在其1.5°C特別報告中表示,1.5°C途徑需要在2030年將碳排降至2010年水平的45%,並在2050年達到淨零。

過去(實線)和未來各種不同情境下,來自能源和工業的全球二氧化碳排放量:IEA STEPS(黑色虛線)、IEA SDS(粗紅線)、IPCC升溫1.5℃內途徑,沒有或有限的升溫度超標(細黃線)、IPCC升溫超過1.5C途徑(藍色)以及IPCC升溫2C途徑(灰色)。低於零的值表示負排放,即來自能源和工業的二氧化碳增加量少於移除量,這裡主要是指有碳捕獲和儲存(BECCS)的生物能。資料來源:國際能源署《 2019年世界能源展望》和Carbon Brief對IPCC 1.5℃暖化特別報告的簡要分析。圖片由Carbon Brief用Highcharts繪製。

根據IEA資料,SDS「使全球氣溫上升控制在遠低於2°C……並力求控制在1.5°C以內,完全符合《巴黎協定》目標」。還提供了兩種表現可以超越SDS,同時升溫保持在1.5°C以下的選擇。

「力求」不一定是實現目標,而是朝著目標前進,或者是非常接近1.5°C-只要有額外的行動。

除了WEO中心觀點STEPS外,巴黎協定中所謂的「非常接近」也是飽受非政府組織、科學家、商業團體和其他組織批評的語言。他們今年四月寫信呼籲IEA模擬出有66%機率將升溫限制在1.5°C的情境。

這封信的其中一位作者、倫敦帝國理工學院格蘭瑟姆研究所氣候變遷和環境講師羅傑爾(Joeri Rogelj)博士說,SDS和1.5°C不一致,和《巴黎協定》也有些面向不同。

羅傑爾是IPCC 1.5°C特別報告第二章的協調主要作者,也是IPCC即將發布的第六次評估報告中第一工作組的主要作者。

他告訴Carbon Brief,巴黎協定的「力求1.5°C」至少有兩種可能的解釋,一種是將峰值升溫限制在1.5°C,另一種是可以超過再降回。「把錯過目標納入計畫當中,不能合理解釋成完全符合《巴黎協定》,」羅傑爾說。

他還指出了協定的第4條,致力於在人為碳排放源與所有溫室氣體匯之間達到「平衡」。要實現這個目標可能需要淨負​碳排​,SDS沒有達成這一點的詳細途徑。

負碳排可以透過技術解決方案實現,如帶有碳捕集與封存的生物能源(BECCS),也可透過自然氣候解決方案達成,如綠化。

IEA表示,負排放確實是SDS之下達成1.5°C的一種方法,總共需要清除大約3000億噸的二氧化碳(GtCO2)才能彌補這個差距。然而IEA也承認,大規模部署負碳排設備的永續性和可交付性的確存在隱憂。

WEO說:

考慮到負排放技術的問題,構建一個超越SDS、2050年實現零碳排放,並有50%的機率將升溫限制在1.5°C,而無需依賴淨負碳排的情境是有可能的。

(這個情境已經有人做出,收錄在IPCC的1.5°C報告和上圖中。)

IEA表示,要超越SDS,全世界必須正面對抗那些最困難的領域,如航空、重工業和建築供熱,包括全面性的建築改造、工業過程新技術的開發和改造。

IEA表示,這「不只是擴大SDS中的變革而已」,而是要「面對非常困難且難以克服的挑戰」,有一些領域需要社會大眾的接受度和行為改變:

「這不是能源業內部就能做到的事,而是整個社會的任務……需要跨非常多領域進行大規模變革,這將直接影響幾乎每個人的生活。」

雖然有點挑戰性,但如果IEA能建構出1.5°C情境,政策規劃人員可以參考IEA模型來瞭解各種能源和氣候選擇。隨著各國政府根據《巴黎協定》重新考慮其氣候承諾,並在2020年推出新一輪的國家自主減排計畫,這個參考資料將顯得很重要。

煤炭的變化

報告內有去年版本至今的各種變動,反映相對於基準年的變化-2018年需求增加力道異常強勁-以及新增或修訂的政策。

IEA再次下調了STEPS下的煤炭需求前景,如下圖所示(紅線)。但是煤炭近期前景提高了,部分原因是中國重新依賴高污染產業來支撐增長緩慢。

全球煤炭需求歷史(黑線,百萬噸石油當量)和IEA前一版中心觀點情境的未來成長(藍色色塊)。今年的STEPS以紅色標示,SDS以黃色標示。資料來源:國際能源署《 2019年世界能源展望》和前一版報告。Carbon Brief使用Highcharts繪製。

照STEPS的計畫和政策,儘管近期需求有所增長,今年燃煤用量將會低於2014年的峰值,但仍遠高於SDS之下、暖化遠低於2°C途徑的水準(上圖黃線)。

STEPS之下,美國和歐盟等已開發經濟體煤炭用量快速下降,但印度需求增長是保持全球煤炭用量穩定的關鍵因素之一。

印度這波成長的部分原因是大量新火力發電廠興建中,到2040年將打造出232GW的容量,成長一倍,佔全球新增容量的1/3。

IEA表示,如果電池儲存成本的下降速度快於預期,印度的煤電容量成長將被「大幅削減」。 IEA表示,太陽能和廉價的儲存技術可以「重塑印度電力結構的演變」,並提供「非常引人注目的經濟和環境主張」。

印度的高壓電塔。照片來源: 。

值得注意的另一點是,印度目前燃煤容量只有85GW,IEA預計的新燃煤容量卻高達232GW,其中有1/4已經被凍結多年。

自2010年以來,由於廉價再生能源的競爭、公用事業公司財務困境和公眾的反對,有額外510GW的新煤電廠計畫被取消。

此外,印度政府一再高估了電力需求的增長,現有煤電容量的運行時間不到2/3。2019年至今的數據顯示,印度煤炭發電量可能正在下降。

印度政府最近宣布了一個相當積極的目標,太陽能、風能和生質能的容量要達到450GW,最快2030年達成。IEA的STEPS到2030年僅增加344GW。根據近期Carbon Brief的分析,如果能夠達到這個目標,那麼風能、太陽能和其他低碳能源可以在不增加新煤電的情況下,滿足日益增長的需求。(2/3,未完待續)

‘Profound shifts’ underway in energy system, says IEA World Energy Outlook (2/3) by Simon Evans

CO2 emissions

In the STEPS, global CO2 emissions from energy would continue to rise from the they reached in 2018, putting the world on track for upwards of 2.7C of warming this century. This emissions trajectory is shown with the dashed black line in the chart, below.

In contrast, CO2 declines quickly in the SDS (thick red line) to 17% below 2010 levels by 2030, 48% by 2040 and 68% by 2050. According to the IEA, this is “on course for net-zero emissions by 2070” and corresponds to a 50% likelihood of limiting warming to 1.65C, or a 66% chance of 1.8C.

This trajectory is less ambitious than most pathways to 1.5C with no or limited overshoot (yellow lines, below). In its on 1.5C, the (IPCC) said this would need CO2 to fall 45% below 2010 levels by 2030 and to net-zero by 2050.

Global CO2 emissions from energy and industrial processes in the past (solid black line) and under a range of different scenarios for the future: IEA STEPS (dashed black); IEA SDS (thick red line); IPCC pathways limiting warming to 1.5C this century with no or limited temperature overshoot (thin yellow lines); pathways to 1.5C with high overshoot (blue); and IPCC 2C pathways (grey). Values below zero indicate negative emissions, where residual CO2 from energy and industry is more than offset by removals, here primarily bioenergy with carbon capture and storage (BECCS). Source: IEA and Carbon Brief analysis of the for the IPCC of warming. Chart by Carbon Brief using .

According to the IEA, the SDS charts “a path fully aligned with the by holding the rise in global temperatures to ‘well below 2C…and pursuing efforts to limit [it] to 1.5C’”. It also offers two options for going beyond the SDS to keep warming below 1.5C.

This form of words implies either that “pursue” means to head towards a goal, without necessarily reaching it, or that the SDS is aligned with 1.5C – so long as it is accompanied by additional action.

Along with the WEO’s central focus on the STEPS pathway, the statement on Paris “alignment” is at the heart of from a group of NGOs, scientists, business groups and others. In an , they called for the IEA to develop a scenario with a 66% chance of limiting warming to 1.5C.

One of the letter’s authors, , a lecturer in climate change and the environment at the , says the SDS is “inconsistent with 1.5C and several aspects of the Paris Agreement”.

Rogelj was a coordinating lead author on chapter two of the IPCC and is a for working group one on the IPCC’s forthcoming .

He tells Carbon Brief that there are at least two potential interpretations of the Paris ambition to “pursue efforts towards 1.5C”. One is that of limiting peak warming to 1.5C and the other is overshooting this level before returning below 1.5C, Rogelj says: “Planning to simply miss it is not a reasonable interpretation for a scenario that wants to be fully aligned with the Paris Agreement.”

He also points to of the deal, which commits to reaching a “balance” between human sources and sinks of all greenhouse gases. This goal is likely to require net-negative CO2, for which the SDS provides no detailed pathway.

Negative CO2 emissions could be provided via , such as (BECCS), or using “”, such as afforestation.

The IEA says that negative emissions do indeed offer one way that the SDS could become aligned to a 1.5C limit. A cumulative total of around 300bn tonnes of CO2 (GtCO2) would need to be removed to bridge this gap, it adds. There are over the sustainability and deliverability of such extensive deployment, however, and these are acknowledged by the IEA.

The WEO says:

“[I]t would be possible in the light of concern about [negative emissions technologies] to construct a scenario that goes further than the Sustainable Development Scenario and delivers a 50% chance of limiting warming to 1.5C without any reliance on net-negative emissions on the basis of a zero carbon world by 2050.”

[Other groups have developed a limited of that already do this, which are included in the IPCC’s and the figure above.]

To go beyond its SDS, the IEA says the world would need to tackle “hard to abate” sectors, such as aviation, heavy industry and heat for buildings. This would include near-universal building retrofits and the development and retrofitting of new technologies for industrial processes.

The IEA says this “would not amount to a simple extension” of the changes in the SDS, instead “pos[ing] challenges that would be very difficult and very expensive to surmount.” It adds that tackling some of these areas would require social acceptance and behavioural change:

“This is not something that is within the power of the energy sector alone to deliver. It would be a task for society as a whole…Change on a massive scale would be necessary across a very broad front, and would impinge directly on the lives of almost everyone.”

If the IEA were to develop a 1.5C scenario, despite the challenges it would present, then the agency’s modelling could be used by policymakers to inform their energy and climate choices. Such guidance would be pertinent as governments reconsider their climate pledges under the Paris Agreement, with a fresh round of “” due in 2020.

Coal changes

The outlook includes various changes since last year’s edition, reflecting shifts in the base year – there was growth in demand in 2018 – and new or amended policy.

As a result, the IEA has once again revised down its outlook for coal demand in the central STEPS pathway, as the chart below shows (red line). However, it has also raised its near-term outlook for coal, in part due to China’s renewed industries to prop up flagging growth.

Historical global coal demand (black line, millions of tonnes of oil equivalent) and the IEA’s previous central scenarios for future growth (shades of blue). This year’s STEPS is shown in red and the SDS is in yellow. Source: IEA and previous editions of the outlook. Chart by Carbon Brief using .

Despite the near-term increase in expected demand, this year’s outlook affirms that coal use would remain below the global peak reached in 2014, if stated plans and policies are met as per the STEPS. Nevertheless, this would leave coal demand significantly above the level in its SDS, where warming is limited to well-below 2C (yellow line, above).

According to the STEPS, rising is one of the key factors holding global coal use steady, despite rapid falls in developed economies, such as the US and EU.

Part of the reason for this increase in India is a large expected buildout of new coal-fired power stations, with 232GW of capacity built by 2040 in the STEPS, roughly doubling its and accounting for a third of global additions.

The IEA says India’s coal capacity growth could be cut “sharply”, if declines in the cost of battery storage are faster than expected. Solar and cheap storage could “reshape the evolution of India’s power mix”, the IEA says, offering a “very compelling economic and environmental proposition”.

It is also worth comparing the 232GW of new coal capacity expected by the IEA, with India’s current pipeline of , of which a quarter has been frozen in construction for years.

Another 510GW of new coal has been cancelled since 2010 due to competition from cheaper renewables, financial distress at utility firms and public opposition.

In addition, the Indian government has electricity demand growth, meaning existing coal capacity is running less than two-thirds of the time. Moreover, data for 2019 to date suggests India’s electricity .

The Indian government recently a highly ambitious target for solar, wind and biomass capacity to reach 450GW, potentially as soon as 2030, when the IEA STEPS outlook sees just 344GW having been added. If this target is met, then wind, solar and other low-carbon sources could largely meet rising demand without new coal, according to recent .

※ 全文及圖片詳見:()

作者

如果有一件事是重要的,如果能為孩子實現一個願望,那就是人類與大自然和諧共存。

於特有生物研究保育中心服務,小鳥和棲地是主要的研究對象。是龜毛的讀者,認為龜毛是探索世界的美德。

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※想知道網站建置網站改版該如何進行嗎?將由專業工程師為您規劃客製化網頁設計後台網頁設計

※不管是台北網頁設計公司台中網頁設計公司,全省皆有專員為您服務

※Google地圖已可更新顯示潭子電動車充電站設置地點!!

※帶您來看台北網站建置台北網頁設計,各種案例分享

※別再煩惱如何寫文案,掌握八大原則!

2020年代中期 再生能源將取代燃煤成發電主力 | 解讀《 2019年世界能源展望》報告3/3

環境資訊中心外電;姜唯 翻譯;林大利 審校;稿源:Carbon Brief 前言:國際能源署(IEA)2019年《世界能源展望》報告達810頁,其特點在於描繪出「承諾政策情境」(Stated Policies Scenario, STEPS),反映政府已經說出口的政策的效果。相對地,報告的「永續發展情境」(Sustainable Development Scenario, SDS)描繪出更積極朝向友善氣候的條件,若在此情境下,全球升溫有50%機率限制在1.65°C之內。
太陽光電板設置作業。照片來源:

超大型太陽能?

()根據IEA的STEPS情境,到2020年代中期,再生能源將取代煤炭成為最大的電力來源。到2040年,低碳能源將滿足全世界一半以上的電力需求,在SDS情境中甚至達到85%。

(不過,值得重申的是,今日電力僅佔總能源消耗的1/5,到2040年,這個數字在STEPS中將上升到24%,在SDS中將上升到31%。這是僅靠再生能源無法解決氣候挑戰的諸多原因之一。)

值得注意的是,今年的STEPS中,再生能源的前景大幅提高,2040年的太陽能總量提高了23%,風能提高了11%。非水電再生能源的增加了8%(下圖中的紅線),在2030年代後期超過了煤炭。

再生能源產量的成長大部分被增加的需求用掉,表示其他來源的發電相對不受影響。Carbon Brief的分析顯示,相對於去年的展望報告,2040年需求成長主要來自於2018基準年的需求增加,年複合成長率為2%。

各種能源全球發電量(十億度,TWh,即太瓦時)。 WEO 2019的歷史資料和STEPS以實線標示,WEO 2018以虛線標示。資料來源:國際能源署《 2019年世界能源展望》及上一版。Carbon Brief用Highcharts繪製。

WEO解釋:

由於成本持續降低,太陽光電成為2020年中國和印度最具競爭力的電力來源。到2030年,太陽能在歐盟和美國與其他能源的差距將大大縮小。在STEPS之下,2018年到2030年全球太陽光電的平均成本(均化成本)下降了約50%。

此外WEO強調,風能和太陽能的成本下降使「直接從煤炭轉往再生能源有更堅強的經濟理由」,而不是將天然氣當作通往低碳能源的過渡能源。

它還提到,美國新公布的海上風電競標,歐盟各地的競標價格低於預期,中國再生能源零補貼的趨勢也有所減弱。

IEA最近發表了一份關於海上風電前景的深度探討報告。IEA認為海上風電的技術潛力可滿足當今電力需求的好幾倍,成本更將在十年內與化石燃料相當。

IEA表示,隨著風能和太陽能在電力領域的發展,將面臨越來越多的挑戰:「政策制定者和監管機構必須迅速採取行動,以跟上技術變革的步伐和不斷成長的需求,以確保電力系統的靈活運作。」

太陽能傳說

儘管如前所述,今年的STEPS大幅上修2040年太陽能產出,但與其他預測相比,IEA對該技術的展望相對保守。

IEA對太陽能前景的預測受到許多批評。如下一個圖表的藍色色塊,IEA連續好幾個版本的前景報告上修太陽能容量成長。

(請注意,圖表顯示的是扣除退役後的淨增加。由於絕大多數太陽能容量的增加發生在近期,因此最初期可以忽略不計。IEA假設到2040年將有298GW的太陽能容量退役,也就是說在2030年代和之後,實際增加量會增加,而不是像下面的淨增加量表所示的那樣相對平穩。)

全世界太陽能年淨增加量(百萬瓩,GW)。紅色表示2019年的歷史資料和預估,而藍色表示各版本WEO的中心觀點預測。 WEO 2019 STEPS以黑色標示。資料來源:國際能源署《 2019年世界能源展望》和該報告的過去版本。Carbon Brief使用Highcharts繪製。

IEA將這些連續上修歸因於政府政策隨時間變化,尤其是中國的變化,中國是世界上最大的太陽能市場。

IEA解釋,繼2018年太陽能增長略顯疲軟後,「重新加速年度太陽能佈署,並加大力道確保將太陽能所發電力穩定進入電力系統,對於實現氣候目標和其他永續發展目標至關重要」 。

IEA相對保守的太陽能前景預測似乎部分取決於其對各種發電技術的標準加權平均資本成本的計算,視每個國家的發展階段,設定在7%到8%。

正如IEA對海上風電所做的估算,這可能對特定計畫的均化電力成本(LCOE)產生非常大的影響。 (歐洲海上風電的實際資本成本已接近4%,足以將其LCOE從每千度(MWh)140美元左右降低到100美元。)

另一個因素可能是IEA將重點放在系統「價值」上,而不是前期成本。IEA在WEO 2018發展出的「VALCOE」指標是這麼說明的。

IEA表示,降低成本並不保證能維持競爭力,「因為隨著其發電比例的增加,太陽能的系統價值相對於系統平均值而言往往會下降」。

因為太陽能輸出集中在每天中午時段,容量增加使供電增加,也部分影響了既有太陽能板創造的電價。

有些預測報告同樣考慮了這些因素,卻看好太陽能發電量的增長。到2040年,IEA的STEPS之下每年新增的太陽能不足140GW,而彭博新能源基金會(BloombergNEF)的新能源展望報告則認為,屆時新增的太陽能將超過300GW。這個數字與IEA的SDS中的佈署相同。

彭博新能源基金會還更看好風電容量的增長,預測到2050年,煤炭的電力輸出將下降一半,而非像IEA STEPS所預測的保持穩定。(系列專文3/3)

‘Profound shifts’ underway in energy system, says IEA World Energy Outlook (3/3) by Simon Evans

Supersized solar?

Elsewhere in the electricity sector, the IEA’s central STEPS sees renewables surging and overtaking coal as the largest source of power . By 2040, low-carbon sources would be supplying more than half of the world’s electricity needs – rising to 85% in the SDS.

(It is worth reiterating, however, that electricity accounts for only a fifth of final energy consumption today, a figure that rises to 24% by 2040 in the STEPS or 31% in the SDS. This is one of the many reasons why renewables alone cannot solve the climate challenge.)

Notably, this year’s STEPS has significantly increased the prospects for renewables, raising the solar total for 2040 by 23% and that for wind by 11%. This revision, adding 8% to the total for non-hydro renewables (red lines in the chart, below), sees them overtaking coal in the late 2030s.

The increase in expected renewable output is mostly absorbed by higher demand, meaning that generation from other sources is relatively unaffected. Carbon Brief analysis suggests the increase in 2040 demand relative to last year’s outlook is mainly due to higher demand in the base year 2018, which gets compounded by 2% annual growth.

Global electricity generation, by fuel, terawatt hours. Historical data and the STEPS from WEO 2019 are shown with solid lines while the WEO 2018 is shown with dashed lines. Source: IEA and last year’s edition. Chart by Carbon Brief using .

The WEO explains:

“As a result of continued cost reductions, solar PV becomes the most competitive source of electricity in 2020 in China and India, and largely closes the gap with other sources by 2030 in the European Union and United States. In the Stated Policies Scenario, the global average [levelised cost] of solar PV declines by about 50% from 2018 to 2030.”

It adds that cost declines for wind and solar are “bolstering the economic case for switching directly from coal to renewables”, rather than using gas as a “bridge” to low-carbon sources.

It also points to newly announced for offshore wind, in auctions around the EU and a softening of towards subsidy-free renewables.

The IEA recently published an of the prospects for offshore wind, which it says “has the technical potential to meet today’s electricity demand many times over” at costs set to be competitive with fossil fuels within a decade.

THREAD

Offshore wind has “near limitless” potential & is “set to be competitive with fossil fuels within the next decade”, as costs fall 60% by 2040.

Turbines will soon be as large as the Eiffel Tower.

Pretty amazing stuff from today’s new report.

— Simon Evans (@DrSimEvans)

The IEA says there will be an increasing need to address challenges posed by variable wind and solar as they take hold of the electricity sector: “Policy makers and regulators will have to move fast to keep up with the pace of technological change and the rising need for flexible operation of power systems.”

Solar saga

Despite the large upwards revision in solar output in 2040 under this year’s STEPS, noted above, the IEA’s outlook for the technology remains relatively conservative compared with some others.

The IEA’s outlooks for solar have become something of a for critics of the agency’s work. It has made upwards revisions for solar capacity growth in each successive edition of the outlook, shown in shades of blue in the chart, below.

(Note that the chart shows additions net of retirements. These are initially negligible as the vast majority of solar capacity growth has been recent. The IEA assumes 298GW of solar retirements to 2040, suggesting it expects capacity to switch off after around 25 years. This means that actual additions and beyond, rather than apparently remaining relatively flat as in the net additions chart below.)

Annual net additions of solar capacity around the world, gigawatts. Historical data and an estimate for 2019 are shown in red while central outlooks from successive editions of the WEO are shown in shades of blue. The WEO 2019 STEPS is shown in black. Source: IEA and previous editions of the outlook. Chart by Carbon Brief using .

The IEA attributes these successive upwards revisions largely to shifts in government policy over time, in particular pointing to changes in China, which is the world’s largest market for solar.

Myth 2: underestimates renewables growth.
-False. Additions of renewables lead all sources in all scenarios. Track back and China’s policy changes accelerated global growth. Unfortunately, in the rest of the world, renewables are behind (!) the STEPS equivalent from WEO2009

— Brent Wanner (@WannerBrent)

The IEA argues that following slightly weaker solar growth in 2018, “a renewed acceleration in annual solar PV deployment, alongside enhanced efforts to ensure smooth integration of the resulting solar generation into power systems, is essential to reach climate targets and other sustainable development goals”.

The IEA’s relatively conservative outlook for solar appears to rest partly on its use of a cost of capital for all electricity generation technologies, set at 7-8% depending on each country’s stage of development.

This can have a very large impact on the levelised cost of electricity (LCOE) for a given project, as the IEA with reference to offshore wind. (Actual costs of capital for offshore wind in Europe have been closer to 4%, enough to cut its LCOE from around $140 per megawatt hour to $100/MWh.)

Another factor could be the IEA focus on system “value” rather than , illustrated by the “” metric it developed for the WEO 2018.

The agency says that cost reductions do not guarantee continued competitiveness “because the system value of solar PV tends to decline relative to the system average as its share of generation rises”.

This is because solar output is concentrated in the middle of the day, with additional capacity adding to supply and so partially eroding the price commanded by already-built solar panels.

Despite also considering these sorts of issues, some other outlooks are on solar capacity growth. Whereas the IEA’s STEPS has solar additions of less than 140GW each year by 2040, the  sees solar additions topping 300GW by then. This higher figure is in line with deployment in the IEA’s target-focused SDS.

BloombergNEF is also more bullish on wind capacity growth, with the result that its outlook has electricity output from coal falling by half in 2050, rather than holding steady as in the IEA’s STEPS.

Simon Evans was one of more than 250 external peer reviewers that read sections of the World Energy Outlook in draft form.

※ 全文及圖片詳見:()

作者

如果有一件事是重要的,如果能為孩子實現一個願望,那就是人類與大自然和諧共存。

於特有生物研究保育中心服務,小鳥和棲地是主要的研究對象。是龜毛的讀者,認為龜毛是探索世界的美德。

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※如何讓商品強力曝光呢? 網頁設計公司幫您建置最吸引人的網站,提高曝光率!!

網頁設計一頭霧水??該從何著手呢? 找到專業技術的網頁設計公司,幫您輕鬆架站!

※想知道最厲害的台北網頁設計公司推薦台中網頁設計公司推薦專業設計師”嚨底家”!!

※幫你省時又省力,新北清潔一流服務好口碑

※別再煩惱如何寫文案,掌握八大原則!

承諾氣候行動 裴洛西率國會代表團反對川普:美國還在

環境資訊中心綜合外電;姜唯 編譯;林大利 審校

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※想知道網站建置網站改版該如何進行嗎?將由專業工程師為您規劃客製化網頁設計後台網頁設計

※不管是台北網頁設計公司台中網頁設計公司,全省皆有專員為您服務

※Google地圖已可更新顯示潭子電動車充電站設置地點!!

※帶您來看台北網站建置台北網頁設計,各種案例分享

※別再煩惱如何寫文案,掌握八大原則!

理解PostgreSQL的模式、表、空間、用戶間的關係

在平時的工作中,我們經常接觸到數據庫表用戶以及角色的使用,由於經常使用默認的數據庫表空間模式(Schema),所以我們往往忽略了數據庫表空間和模式的概念以及作用。

接下來,先介紹一下模式和表空間的定義以及作用。

什麼是Schema?

一個數據庫包含一個或多個已命名的模式,模式又包含表。模式還可以包含其它對象, 包括數據類型函數操作符等。同一個對象名可以在不同的模式里使用而不會導致衝突; 比如,herschemamyschema都可以包含一個名為mytable的表。 和數據庫不同,模式不是嚴格分離的:只要有權限,一個用戶可以訪問他所連接的數據庫中的任意模式中的對象。

我們需要模式的原因有好多:

  • 允許多個用戶使用一個數據庫而不會幹擾其它用戶。
  • 把數據庫對象組織成邏輯組,讓它們更便於管理。
  • 第三方的應用可以放在不同的模式中,這樣它們就不會和其它對象的名字衝突。

模式類似於操作系統層次的目錄,只不過模式不能嵌套。

什麼是表空間?

表空間是實際的數據存儲的地方。一個數據庫schema可能存在於多個表空間,相似地,一個表空間也可以為多個schema服務。

通過使用表空間,管理員可以控制磁盤的布局。表空間的最常用的作用是優化性能,例如,一個最常用的索引可以建立在非常快的硬盤上,而不太常用的表可以建立在便宜的硬盤上,比如用來存儲用於進行歸檔文件的表。

PostgreSQL表空間、數據庫、模式、表、用戶、角色之間的關係

角色與用戶的關係

PostgreSQL中,存在兩個容易混淆的概念:角色/用戶。之所以說這兩個概念容易混淆,是因為對於PostgreSQL來說,這是完全相同的兩個對象。唯一的區別是在創建的時候:

1.我用下面的psql創建了角色custom:

CREATE ROLE custom PASSWORD 'custom';

接着我使用新創建的角色custom登錄,PostgreSQL給出拒絕信息:

FATAL:role 'custom' is not permitted to log in.

說明該角色沒有登錄權限,系統拒絕其登錄

2.我又使用下面的psql創建了用戶guest:

CREATE USER guest PASSWORD 'guest';

接着我使用guest登錄,登錄成功

難道這兩者有區別嗎?查看文檔,又這麼一段說明:CREATE USER is the same as CREATE ROLE except that it implies LOGIN. —-CREATE USER除了默認具有LOGIN權限之外,其他與CREATE ROLE是完全相同的。

為了驗證這句話,修改custom的權限,增加LOGIN權限:

ALTER ROLE custom LOGIN;

再次用custom登錄,成功!那麼事情就明了了:

CREATE ROLE custom PASSWORD ‘custom’ LOGIN 等同於 CREATE USER custom PASSWORD ‘custom’.

這就是ROLE/USER的區別。

數據庫與模式的關係

模式(schema)是對數據庫(database)邏輯分割。

在數據庫創建的同時,就已經默認為數據庫創建了一個模式–public,這也是該數據庫的默認模式。所有為此數據庫創建的對象(表、函數、試圖、索引、序列等)都是創建在這個模式中的:

1.創建一個數據庫mars

CREATE DATABASE mars;

2.用custom角色登錄到mars數據庫,查看數據庫中的所有模式:\dn

显示結果只有public一個模式。

3.創建一張測試表

CREATE TABLE test(id integer not null);

4.查看當前數據庫的列表:\d;

显示結果是表test屬於模式public.也就是test表被默認創建在了public模式中。

5.創建一個新模式custom,對應於登錄用戶custom

CREATE SCHEMA custom;

ALTER SCHEMA custom OWNER TO custom;

6.再次創建一張test表,這次這張表要指明模式

CREATE TABLE custom.test (id integer not null);

7.查看當前數據庫的列表: \d

显示結果是表test屬於模式custom.也就是這個test表被創建在了custom模式中。

得出結論是:數據庫是被模式(schema)來切分的,一個數據庫至少有一個模式,所有數據庫內部的對象(object)是被創建於模式的。用戶登錄到系統,連接到一個數據庫后,是通過該數據庫的search_path來尋找schema的搜索順序,可以通過命令SHOW search_path;具體的順序,也可以通過SET search_path TO 'schema_name'來修改順序。

官方建議是這樣的:在管理員創建一個具體數據庫后,應該為所有可以連接到該數據庫的用戶分別創建一個與用戶名相同的模式,然後,將search_path設置為$user,即默認的模式是與用戶名相同的模式。

表空間與數據庫的關係

數據庫創建語句:

CREATE DATABASE dbname;

默認的數據庫所有者是當前創建數據庫的角色,默認的表空間是系統的默認表空間pg_default

為什麼是這樣的呢?

因為在PostgreSQL中,數據的創建是通過克隆數據庫模板來實現的,這與SQL SERVER是同樣的機制。由於CREATE DATABASE dbname並沒有指明數據庫模板,所以系統將默認克隆template1數據庫,得到新的數據庫dbname。(By default, the new database will be created by cloning the standard system database template1)

template1數據庫的默認表空間是pg_default,這個表空間是在數據庫初始化時創建的,所以所有template1中的對象將被同步克隆到新的數據庫中。

相對完整的語法應該是這樣的:

CREATE DATABASE dbname TEMPLATE template1 TABLESPACE tablespacename;
ALTER DATABASE dbname OWNER TO custom;

1.連接到template1數據庫,創建一個表作為標記:

CREATE TABLE test(id integer not null);

向表中插入數據

INSERT INTO test VALUES (1);

2.創建一個表空間:

CREATE TABLESPACE tsmars OWNER custom LOCATION '/tmp/data/tsmars';

在此之前應該確保目錄/tmp/data/tsmars存在,並且目錄為空。

3.創建一個數據庫,指明該數據庫的表空間是剛剛創建的tsmars

CREATE DATABASE dbmars TEMPLATE template1 OWNERE custom TABLESPACE tsmars;
ALTER DATABASE dbmars OWNER TO custom;

4.查看系統中所有數據庫的信息:\l+

可以發現,dbmars數據庫的表空間是tsmars,擁有者是custom;

仔細分析后,不難得出結論:

在PostgreSQL中,表空間是一個目錄,裏面存儲的是它所包含的數據庫的各種物理文件

總結

表空間是一個存儲區域,在一個表空間中可以存儲多個數據庫,儘管PostgreSQL不建議這麼做,但我們這麼做完全可行。一個數據庫並不知直接存儲表結構等對象的,而是在數據庫中邏輯創建了至少一個模式,在模式中創建了表等對象,將不同的模式指派該不同的角色,可以實現權限分離,又可以通過授權,實現模式間對象的共享,並且還有一個特點就是:public模式可以存儲大家都需要訪問的對象。

表空間用於定義數據庫對象在物理存儲設備上的位置,不特定於某個單獨的數據庫。數據庫是數據庫對象的物理集合,而schema則是數據庫內部用於組織管理數據庫對象的邏輯集合,schema名字空間之下則是各種應用程序會接觸到的對象,比如表、索引、數據類型、函數、操作符等。

角色(用戶)則是數據庫服務器(集群)全局範圍內的權限控制系統,用於各種集群範圍內所有的對象權限管理。因此角色不特定於某個單獨的數據庫,但角色如果需要登錄數據庫管理系統則必須連接到一個數據庫上。角色可以擁有各種數據庫對象。

關注公眾號:JAVA九點半課堂,這裡有一批優秀的技術大牛,為你提供方向,提供資源!加入我們,一起探討技術,共同進步!回復“資料”獲取 2T 行業最新資料!

本站聲明:網站內容來源於博客園,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※想知道網站建置網站改版該如何進行嗎?將由專業工程師為您規劃客製化網頁設計後台網頁設計

※不管是台北網頁設計公司台中網頁設計公司,全省皆有專員為您服務

※Google地圖已可更新顯示潭子電動車充電站設置地點!!

※帶您來看台北網站建置台北網頁設計,各種案例分享

※別再煩惱如何寫文案,掌握八大原則!

(25)ASP.NET Core EF查詢(複雜查詢運算符、原生SQL查詢、異步查詢)

1.複雜查詢運算符

在生產場景中,我們經常用到LINQ運算符進行查詢獲取數據,現在我們就來了解下生產場景經常出現幾種複雜查詢運算符。

1.1聯接(INNER JOIN)

藉助LINQ Join運算符,可根據每個源的鍵選擇器連接兩個數據源,並在鍵匹配時生成值的元組。

var query = from blog in _context.Set<Blog>()
            join post in _context.Set<Post>()
                on blog.BlogId equals post.BlogId
            select new { blog, post };

SQL:

SELECT [blog].[BlogId], [blog].[Createtime], [blog].[Updatetime], [blog].[Url], [post].[PostId], [post].[BlogId], [post].[Content], [post].[Title]
FROM [Blog] AS [blog]
INNER JOIN [Post] AS [post] ON [blog].[BlogId] = [post].[BlogId]

SQL Server Profiler:

1.2左聯接(Left Join)

雖然Left Join不是LINQ運算符,但關係數據庫具有常用於查詢的Left Join的概念。LINQ查詢中的特定模式提供與服務器上的LEFT JOIN相同的結果。

var query = from blog in _context.Set<Blog>()
            join post in _context.Set<Post>()
                on blog.BlogId equals post.BlogId into grouping
            from post in grouping.DefaultIfEmpty()
            select new { blog, post };

SQL:

SELECT [blog].[BlogId], [blog].[Createtime], [blog].[Updatetime], [blog].[Url], [post].[PostId], [post].[BlogId], [post].[Content], [post].[Title]
FROM [Blog] AS [blog]
LEFT JOIN [Post] AS [post] ON [blog].[BlogId] = [post].[BlogId]

SQL Server Profiler:

1.3分組(GroupBy)

LINQ GroupBy運算符創建IGrouping<TKey, TElement>類型的結果,其中TKey和TElement可以是任意類型。此外,IGrouping實現了IEnumerable<TElement>,這意味着可在分組后使用任意LINQ運算符來對其進行組合。

var query = from blog in _context.Set<Blog>()
            group blog by blog.Url into g
            select new
            {
                g.Key,
                Count = g.Count()
            };

SQL:

SELECT [blog].[Url] AS [Key], COUNT(*) AS [Count]
FROM [Blog] AS [blog]
GROUP BY [blog].[Url]

SQL Server Profiler:

分組的聚合運算符出現在Where或OrderBy(或其他排序方式)LINQ運算符中。它在SQL中將Having子句用於Where子句。

var query = from blog in _context.Set<Blog>()
            group blog by blog.Url into g
            where g.Count() > 0
            orderby g.Key
            select new
            {
                g.Key,
                Count = g.Count()
            };

SQL:

SELECT [blog].[Url] AS [Key], COUNT(*) AS [Count]
FROM [Blog] AS [blog]
GROUP BY [blog].[Url]
HAVING COUNT(*) > 0
ORDER BY [Key]

SQL Server Profiler:

EF Core支持的聚合運算符如下所示:
●Avg
●Count
●LongCount
●Max
●Min
●Sum

1.4SelectMany

藉助LINQ SelectMany運算符,可為每個外部元素枚舉集合選擇器,並從每個數據源生成值的元組。

var query0 = from b in _context.Set<Blog>()
                from p in _context.Set<Post>()
                select new { b, p };

var query1 = from b in _context.Set<Blog>()
                from p in _context.Set<Post>().Where(p => b.BlogId == p.BlogId).DefaultIfEmpty()
                select new { b, p };

var query2 = from b in _context.Set<Blog>()
                from p in _context.Set<Post>().Select(p => b.Url + "=>" + p.Title).DefaultIfEmpty()
                select new { b, p };

SQL:

SELECT [b].[BlogId], [b].[Createtime], [b].[Updatetime], [b].[Url], [p].[PostId], [p].[BlogId], [p].[Content], [p].[Title]
FROM [Blog] AS [b]
CROSS JOIN [Post] AS [p]

SELECT [b].[BlogId], [b].[Createtime], [b].[Updatetime], [b].[Url], [t0].[PostId], [t0].[BlogId], [t0].[Content], [t0].[Title]
FROM [Blog] AS [b]
CROSS APPLY (
    SELECT [t].[PostId], [t].[BlogId], [t].[Content], [t].[Title]
    FROM (
        SELECT NULL AS [empty]
    ) AS [empty]
    LEFT JOIN (
        SELECT [p].[PostId], [p].[BlogId], [p].[Content], [p].[Title]
        FROM [Post] AS [p]
        WHERE [b].[BlogId] = [p].[BlogId]
    ) AS [t] ON 1 = 1
) AS [t0]

SELECT [b].[BlogId], [b].[Createtime], [b].[Updatetime], [b].[Url], [t0].[c]
FROM [Blog] AS [b]
CROSS APPLY (
    SELECT [t].[c]
    FROM (
        SELECT NULL AS [empty]
    ) AS [empty]
    LEFT JOIN (
        SELECT ([b].[Url] + N'=>') + [p].[Title] AS [c]
        FROM [Post] AS [p]
    ) AS [t] ON 1 = 1
) AS [t0]

SQL Server Profiler:

好了,這裏就不多寫關於LINQ其他示例了,如果需要了解的小夥伴們,可以移步“”這裏了解。

2.原生SQL查詢

有一些複雜業務場景,使用LINQ查詢可能會導致SQL查詢效率低下並不適用,那麼這時候就需要到原生SQL查詢了。EF Core為我們提供FromSql擴展方法基於原始SQL查詢。 FromSql只能在直接位於DbSet<>上的查詢根上使用。

var blogs = _context.Blog.FromSql("SELECT * FROM dbo.Blog").ToList();

原生SQL查詢可用於執行存儲過程。

var blogs = _context.Blog
    .FromSql("EXECUTE dbo.GetMostPopularBlogs")
    .ToList();

2.1原始SQL查詢使用參數化

向原始SQL查詢引入任何用戶提供的值時,必須注意防範SQL注入攻擊。除了驗證確保此類值不包含無效字符,還要將值與SQL文本參數化處理。
下面的示例通過在SQL查詢字符串中包含形參佔位符並提供額外的實參,將單個形參傳遞到存儲過程。雖然此語法可能看上去像String.Format語法,但提供的值包裝在DbParameter中,且生成的參數名稱插入到指定{0}佔位符的位置。

var url = "http://blogs.msdn.com/webdev";
var blogs = _context.Blog
    .FromSql("EXECUTE dbo.GetMostPopularBlogForUrl {0}", url)
.ToList();

SQL:

exec sp_executesql N'EXECUTE dbo.GetMostPopularBlogForUrl @p0
',N'@p0 nvarchar(4000)',@p0=N'http://blogs.msdn.com/webdev'

SQL Server Profiler:


還可以構造DbParameter並將其作為參數值提供。由於使用了常規SQL參數佔位符而不是字符串佔位符,因此可安全地使用FromSql:

var urlParams = new SqlParameter("Url", "http://blogs.msdn.com/webdev");
var blogs = _context.Blog
    .FromSql("EXECUTE dbo.GetMostPopularBlogForUrl @Url", urlParams)
.ToList();

SQL:

exec sp_executesql N'EXECUTE dbo.GetMostPopularBlogForUrl @Url
',N'@Url nvarchar(28)',@Url=N'http://blogs.msdn.com/webdev'

SQL Server Profiler:

2.2使用LINQ編寫SQL

可使用LINQ運算符在初始的原始SQL查詢基礎上進行組合。EF Core將其視為子查詢,並在數據庫中對其進行組合。下面的示例使用原始SQL查詢,該查詢從表值函數 (TVF) 中進行選擇。然後,使用LINQ進行篩選和排序,從而對其進行組合。

var searchTerm = "http://blogs.msdn.com/visualstudio";
var blogs = _context.Blog
    .FromSql($"SELECT * FROM dbo.Blog")
    .Where(b => b.Url == searchTerm)
    .Include(c=>c.Post)
    .OrderByDescending(b => b.Createtime)
.ToList();

SQL:

exec sp_executesql N'SELECT [b].[BlogId], [b].[Createtime], [b].[Updatetime], [b].[Url]
FROM (
    SELECT * FROM dbo.Blog
) AS [b]
WHERE [b].[Url] = @__searchTerm_1
ORDER BY [b].[Createtime] DESC, [b].[BlogId]',N'@__searchTerm_1 nvarchar(4000)',@__searchTerm_1=N'http://blogs.msdn.com/visualstudio'

exec sp_executesql N'SELECT [b.Post].[PostId], [b.Post].[BlogId], [b.Post].[Content], [b.Post].[Title]
FROM [Post] AS [b.Post]
INNER JOIN (
    SELECT [b0].[BlogId], [b0].[Createtime]
    FROM (
        SELECT * FROM dbo.Blog
    ) AS [b0]
    WHERE [b0].[Url] = @__searchTerm_1
) AS [t] ON [b.Post].[BlogId] = [t].[BlogId]
ORDER BY [t].[Createtime] DESC, [t].[BlogId]',N'@__searchTerm_1 nvarchar(4000)',@__searchTerm_1=N'http://blogs.msdn.com/visualstudio'

SQL Server Profiler:

3.異步查詢

當在數據庫中執行查詢時,異步查詢可避免阻止線程。異步查詢對於在客戶端應用程序中保持響應式UI非常重要。 異步查詢還可以增加Web應用程序中的吞吐量,即通過釋放線程,以處理其他Web應用程序中的請求。

public async Task<IActionResult> Index()
{
    var id1 = Thread.CurrentThread.ManagedThreadId.ToString();

    var blogs = await _context.Blog.ToListAsync();

    var id2 = Thread.CurrentThread.ManagedThreadId.ToString();

    return View(blogs);
}

當我們運行以上代碼時候,通過在關鍵字await上下文加入兩段獲取線程ID代碼,我們會看到如下結果:

看到兩段線程代碼輸出ID結果沒有?從上圖可以觀察到,當我們在進入某個視圖或者方法時候,執行到await某一個方法,當前線程不會一直等待下去,會立馬回收到線程池,供其他地方調用!當該await方法返回數據時候,才從線程池調用空閑線程執行await方法下文餘下的步驟。所以UI界面才不會進入假死狀態。

參考文獻:

本站聲明:網站內容來源於博客園,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※如何讓商品強力曝光呢? 網頁設計公司幫您建置最吸引人的網站,提高曝光率!!

網頁設計一頭霧水??該從何著手呢? 找到專業技術的網頁設計公司,幫您輕鬆架站!

※想知道最厲害的台北網頁設計公司推薦台中網頁設計公司推薦專業設計師”嚨底家”!!

※幫你省時又省力,新北清潔一流服務好口碑

※別再煩惱如何寫文案,掌握八大原則!

不放心東奧食安 南韓擬自運食材、偵測核食

摘錄自2019年12月5日公共電視報導

明年東京奧運,南韓奧會考量到食品安全,計畫購買輻射偵測器,針對代表團在奧運期間可能吃到的食物偵測,也打算運送自家食材前往日本。讓選手不必擔心吃到2011年福島核災可能遭污染的在地食品。

南韓執政共同民主黨議員申東坤說:「我們將從南韓盡可能帶很多食材過去,也因可能過境會面臨困難,例如肉品跟魚。我們會用各種形式帶食物,即使我們獲得在地韓國餐廳支援,我們還是會檢測輻射採取補充措施,供應安全的食品。」       

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※想知道網站建置網站改版該如何進行嗎?將由專業工程師為您規劃客製化網頁設計後台網頁設計

※不管是台北網頁設計公司台中網頁設計公司,全省皆有專員為您服務

※Google地圖已可更新顯示潭子電動車充電站設置地點!!

※帶您來看台北網站建置台北網頁設計,各種案例分享

※別再煩惱如何寫文案,掌握八大原則!

2020年生物多樣性總體檢 15項保育人士尚未關注的重大威脅與機會

環境資訊中心綜合外電;姜唯 編譯;林大利 審校

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※如何讓商品強力曝光呢? 網頁設計公司幫您建置最吸引人的網站,提高曝光率!!

網頁設計一頭霧水??該從何著手呢? 找到專業技術的網頁設計公司,幫您輕鬆架站!

※想知道最厲害的台北網頁設計公司推薦台中網頁設計公司推薦專業設計師”嚨底家”!!

※幫你省時又省力,新北清潔一流服務好口碑

※別再煩惱如何寫文案,掌握八大原則!