我正在玩一个非常简单的程序来获取一系列双打并返回标准偏差.这部分工作但我想让代码更可重用.我想这样做,所以该方法可以接受任何类型的参数,可以被认为是数字并返回标准偏差而不是硬编码双重类型(就像我最初在这个程序中做的那样).如何解决这个问题以及适当的术语是什么?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
double[] avg = { 3.4, 55.6, 10.0, 4.5, 2, 2 };
double x = avg.Average();
//first round of testing
Console.WriteLine("The average of the first array is below ");
Console.WriteLine(x);
Console.WriteLine("below should be the standard deviation!");
Console.WriteLine(CalculateStandardDeviation(avg));
Console.ReadLine();
int[] intAvg = { 4, 3, 5, 6, 2 };
double secondAvg = intAvg.Average();
Console.WriteLine("The average of the second array is below "); …Run Code Online (Sandbox Code Playgroud) 这张照片中颜色变化的意义是什么?

编辑:我指的是滚动条的黄色和绿色区域.
下面的查询是基于一个复杂的视图,视图按我的意愿工作(我不会包含视图,因为我认为它不会对手头的问题有所帮助).我无法做到的是drugCountsinFamilies专栏.我需要它来向我展示distinct drugName每个药物家族的数量.您可以从第一个screencap看到有三个不同的H3A行.在drugCountsInFamilies为H3A应该是3(有三种不同的H3A药物.)

您可以从第二个屏幕截图中看到,第一个屏幕截图中发生的情况drugCountsInFamilies是捕获列出药物名称的行数.

以下是我的问题,对该部分的评论不正确
select distinct
rx.patid
,d2.fillDate
,d2.scriptEndDate
,rx.drugName
,rx.drugClass
--the line directly below is the one that I can't figure out why it's wrong
,COUNT(rx.drugClass) over(partition by rx.patid,rx.drugclass,rx.drugname) as drugCountsInFamilies
from
(
select
ROW_NUMBER() over(partition by d.patid order by d.patid,d.uniquedrugsintimeframe desc) as rn
,d.patid
,d.fillDate
,d.scriptEndDate
,d.uniqueDrugsInTimeFrame
from DrugsPerTimeFrame as d
)d2
inner join rx on rx.patid = d2.patid
inner join DrugTable as dt on dt.drugClass=rx.drugClass
where d2.rn=1 and rx.fillDate …Run Code Online (Sandbox Code Playgroud) public static class LinqExtensions
{
public static double Variance(this IList<double> data)
{
double sumSquares=0;
double avg = data.Average();
foreach (var num in data)
{
sumSquares += (num - avg * num - avg);
}
return sumSquares / (data.Count - 1);
}
public static decimal? Variance<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal?> selector)
{
//where to start for implementing?
}
}
Run Code Online (Sandbox Code Playgroud)
我想为泛型类型做一些LINQ扩展.我知道如何在不使用委托的情况下扩展LINQ,我有几个尚未定义的类型,它们将具有我需要枚举的属性以及诸如方差之类的东西.如何定义我的Variance扩展方法,以便它需要一个委托?
我有一个现有的函数,它执行一些调用HTTP端点的工作,负责管理我的Angular组件中的一些逻辑.需求的来源是,在某种情况下,我们需要调用所有现有逻辑,还要进行另一个HTTP调用.以下是我的尝试的注释版本.
public resolveComponent(action: string) {
//if called with no parameters, don't do anything
//otherwise, call one of the two endpoints.
let preAction = (x: any) => {
if (action === "replay") {
return this.remediationService
.replayRemediation(this.workflow.Id);
}
else if (action === "remove") {
return this.remediationService
.removeRemediation(this.workflow.Id);
}
else {
return of([]);
}
}
this.remediationService
.resolveComponent(component)
.pipe(
//the line below was what I added after new requirement
mergeMap(preAction),
mergeMap(x => {
//grabs updated data from server
return this.remediationService.remediationComponent(component.Id);
})
)
.subscribe((x: SomeModel) …Run Code Online (Sandbox Code Playgroud) 我有一个服务,将返回我的一些配置选项ng-grid.getGridOptions函数获取它所使用的控制器的名称,并返回正确的选项集(为简洁起见,此处仅显示一个选项).
ng-grid选项的服务:
angular.module('services').service('GridOptionsService',function(){
var documents = {
data: 'myData',
enablePaging: true,
showFooter:true,
totalServerItems: 'totalServerItems',
pagingOptions: {
pageSizes: [50,100,200],
pageSize: 50,
currentPage: 1
},
filterOptions: {
filterText: '',
useExternalFilter: false
},
enableCellEdit: false,
enableColumnReordering: true,
enablePinning: false,
showGroupPanel: false,
groupsCollapsedByDefault: true,
enableColumnResize: true,
showSelectionCheckbox: true,
selectWithCheckboxOnly: true,
columnDefs: [
{field:'docId', displayName:'Document ID', cellTemplate: NgGridDomUtil.toLink('#/documents/{{row.getProperty(col.field)}}')},
{field:'docTags', displayName:'Tags'},
{field:'lastSaveDate', displayName:'Last saved'},
{field:'documentVersion', displayName:'Version', width: 120},
{field:'busDocId', displayName:'Customer Doc ID'},
{field:'markedForDelete', displayName:'Deleted', width: 120, cellTemplate: NgGridDomUtil.toCheckbox('{{row.getProperty(col.field)}}')}]
};
var gridOptionManager = {
documents: …Run Code Online (Sandbox Code Playgroud) 所以,我刚刚发现SQL Server 2008不允许您在定义中使用CTE索引视图,但它允许您在视图定义中alter添加查询with schemabinding.有这么好的理由吗?出于某种原因我不知道是否有意义?我的印象是,WITH SCHEMABINDING主要目的是允许您索引视图
新的和改进的更多查询操作
;with x
as
(
select rx.pat_id
,rx.drug_class
,count(*) as counts
from rx
group by rx.pat_id,rx.drug_class
)
select x.pat_id
,x.drug_class
,x.counts
,SUM(c.std_cost) as [Healthcare Costs]
from x
inner join claims as c
on claims.pat_id=x.pat_id
group by x.pat_id,x.drug_class,x.counts
Run Code Online (Sandbox Code Playgroud)
以及创建索引的代码
create unique clustered index [TestIndexName] on [dbo].[MyView]
( pat_id asc, drug_class asc, counts asc)
Run Code Online (Sandbox Code Playgroud) 以下简单程序将找到用户输入的字符串中的最后一个字母,然后删除该点之后的所有内容.所以,如果一个人string....在g应该被删除后输入一切.我有以下作为一个小程序:
class Program
{
static void Main(string[] args)
{
Console.Write("Enter in the value of the string: ");
List<char> charList = Console.ReadLine().Trim().ToList();
int x = charList.LastIndexOf(charList.Last(char.IsLetter)) ;
Console.WriteLine("this is the last letter {0}", x);
Console.WriteLine("This is the length of the string {0}", charList.Count);
Console.WriteLine("We should have the last {0} characters removed", charList.Count - x);
for (int i = x; i < charList.Count; i++)
{
charList.Remove(charList[i]);
}
foreach (char c in charList)
{
Console.Write(c);
}
Console.ReadLine();
}
} …Run Code Online (Sandbox Code Playgroud) 为了便于说明,我有一个简单的Employee类,其中包含多个字段和一个删除Certifications属性中多次出现的方法
public int EmployeeId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
private List<string> certifications = new List<string>();
public List<string> Certifications
{
get { return certifications; }
set { certifications = value; }
}
public List<string> RemoveDuplicates(List<string> s)
{
List<string> dupesRemoved = s.Distinct().ToList();
foreach(string str in dupesRemoved)
Console.WriteLine(str);
return dupesRemoved;
}
Run Code Online (Sandbox Code Playgroud)
RemoveDuplicates方法将删除Employee对象的Certifications属性中的任何重复字符串.现在考虑我是否有一个Employee对象列表.
Employee e = new Employee();
List<string> stringList = new List<string>();
stringList.Add("first");
stringList.Add("second");
stringList.Add("third");
stringList.Add("first");
e.Certifications = …Run Code Online (Sandbox Code Playgroud) 我正在做一个项目,我们已经开始编写 Jasmine 单元测试。这个应用程序,就像任何优秀的 JS 应用程序一样,会异步获取大量数据。我看到 angular 提供了 $httpBackend 来模拟 HTTP 请求。我还读到并听说在控制器中测试 AJAX 请求是一个坏主意,因此 $httpBackend 存在的理由。为什么测试 AJAX 调用不是一个好主意?大型 JS 应用程序如何绕过这个事实?击中实际服务器的实际测试何时发生?
c# ×4
angularjs ×2
javascript ×2
linq ×2
sql ×2
sql-server ×2
t-sql ×2
angular ×1
asp.net ×1
generics ×1
jasmine ×1
rxjs ×1
ssms ×1
unit-testing ×1
view ×1